Part Number Hot Search : 
74479142 M16G45 LA3133 TPCA8 R1343L00 29PL16 TL431 MAD24003
Product Description
Full Text Search
 

To Download AT32UC3A4128S-C1UT Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  32072d?04/2011 features ? high performance, low power 32-bit avr ? microcontroller ? compact single-cycle risc instruction set including dsp instruction set ? read-modify-write instructions and atomic bit manipulation ? performing up to 1.51dmips/mhz ? up to 92dmips running at 66mh z from flash (1 wait-state) ? up to 54 dmips running at 36 mhz from flash (0 wait-state) ? memory protection unit ? multi-layer bus system ? high-performance data transfers on separate buses for increased performance ? 8 peripheral dma channels (pdca) improves speed for peripheral communication ? 4 generic dma channels for high bandwidth data paths ? internal high-speed flash ? 256kbytes, 128kbytes, 64kbytes versions ? single-cycle flash access up to 36mhz ? prefetch buffer optimizing instru ction execution at maximum speed ? 4 ms page programming time and 8ms full-chip erase time ? 100,000 write cycles, 15-year data retention capability ? flash security locks and us er defined configuration area ? internal high-speed sram ? 64kbytes single-cycle access at fu ll speed, connected to cpu local bus ? 64kbytes (2x32kbytes with independent access) on the multi-layer bus system ? interrupt controller ? autovectored low latency interrupt service with programmable priority ? system functions ? power and clock manager including inte rnal rc clock and one 32khz oscillator ? two multipurpose oscillators an d two phase-lock-loop (pll), ? watchdog timer, real-time clock timer ? external memories ? support sdram, sram, nandflash (1-b it and 4-bit ecc), compact flash ? up to 66 mhz ? external storage device support ? multimediacard (mmc v4.3), secu re-digital (sd v2.0), sdio v1.1 ? ce-ata v1.1, fastsd, smartmedia, compact flash ? memory stick: standard format v1.40, pro format v1.00, micro ? ide interface ? one advanced encryption system (aes) for at32uc3a3256s, at32uc3a3128s, at32uc3a364s, at32uc3a4256s, at32uc3a4128s and at32uc3a364s ? 256-, 192-, 128-bit key algorithm, co mpliant with fips pub 197 specifications ? buffer encryption/decryption capabilities ? universal serial bus (usb) ? high-speed usb 2.0 (480mbit/s) device and embedded host ? flexible end-point configuration and management with dedicated dma channels ? on-chip transceivers including pull-ups ? one 8-channel 10-bit analog-to-digital converter, multiplexed with digital ios. ? two three-channel 16-bit timer/counter (tc) ? four universal synchronous/asynchro nous receiver/transmitters (usart) ? fractionnal baudrate generator 32-bit avr ? microcontroller at32uc3a3256s at32uc3a3256 at32uc3a3128s at32uc3a3128 at32uc3a364s at32uc3a364 at32uc3a4256s at32uc3a4256 at32uc3a4128s at32uc3a4128 at32uc3a464s at32uc3a464 preliminary
2 32072d?04/2011 at32uc3a3/a4 ? support for spi and lin ? optionnal support for irda, iso7816, hardwa re handshaking, rs485 in terfaces and modem line ? two master/slave serial peripheral interfaces (spi) with chip select signals ? one synchronous serial protocol controller ? supports i2s and generic frame-based protocols ? two master/slave two-wire interface (twi), 400kbit/s i2c-compatible ? 16-bit stereo audio bitstream ? sample rate up to 50 khz ? qtouch ? library support ? capacitive touch buttons, sliders, and wheels ? qtouch ? and qmatrix ? acquisitionon-chip debug system (jtag interface) ? nexus class 2+, runtime control, non-intrusive data and program trace ? 110 general purpose input/output (gpios) ? standard or high speed mode ? toggle capability: up to 66mhz ? packages ? 144-ball tfbga, 11x11 mm, pitch 0.8 mm ? 144-pin lqfp, 22x22 mm, pitch 0.5 mm ? 100-ball vfbga, 7x7 mm, pitch 0.65 mm ? single 3.3v power supply
3 32072d?04/2011 at32uc3a3/a4 1. description the at32uc3a3/a4 is a complete system-on-chip microcontroller based on the avr32 uc risc processor running at frequencies up to 66mhz. avr32 uc is a high-performance 32-bit risc microprocessor core, designed for cost-s ensitive embedded applications, with particular emphasis on low power consumption, high code density and high performance. the processor implements a memory protection unit (mpu) and a fast and flexible interrupt con- troller for supporting modern operating systems and real-time operating systems. higher computation capabilities ar e achievable using a rich set of dsp instructions. the at32uc3a3/a4 incorporates on-chip flash and sram memories for secure and fast access. 64 kbytes of sram are directly coupled to the avr32 uc for performances optimiza- tion. two blocks of 32 kbytes sram are independently attached to the high speed bus matrix, allowing real ping-pong management. the peripheral direct memory access cont roller (pdca) enables data transfers between peripherals and memories without processor involvement. the pdca drastically reduces pro- cessing overhead when transferring continuous and large data streams. the power manager improves design flexibility and security: the on-chip brown-out detector monitors the power supply, the cpu runs from t he on-chip rc oscillator or from one of external oscillator sources, a real-time clock and its associated timer keeps track of the time. the device includes two sets of three identical 16-bit timer/counter (tc) channels. each chan- nel can be independently programmed to perform frequency measurement, event counting, interval measurement, pulse generation, delay timing and pulse width modulation. 16-bit chan- nels are combined to operate as 32-bit channels. the at32uc3a3/a4 also features many communication interfaces for communication intensive applications like uart, spi or twi. the us art supports different communication modes, like spi mode and lin mode. additionally, a flexible synchronous serial cont roller (ssc) is avail- able. the ssc provides easy access to serial communication protocols and audio standards like i2s. the at32uc3a3/a4 includes a powerfull external bus interface to interface all standard mem- ory device like sram, sdram, nand flash or parallel interfac es like lcd module. the peripheral set includes a high speed mci for sdio/sd/mmc and a hardware encryption module based on aes algorithm. the device embeds a 10-bit adc and a digital audio bistream dac. the direct memory access controller (dmaca) allows high bandwidth data flows between high speed peripherals (usb, external memories, mmc, sdio, ...) and through high speed internal features (aes, in ternal memories). the high-speed (480mbit/s) usb 2.0 device and host interface supports several usb classes at the same time thanks to the rich endpoint configuration. the embedded host interface allows device like a usb flash disk or a usb printer to be directly connected to the processor. this periphal has its own dedicated dma and is perfect for mass storage application. at32uc3a3/a4 integrates a class 2+ nexus 2.0 on-chip debug (ocd) system, with non-intru- sive real-time trace, full-speed read/write memory access in addition to basic runtime control.
4 32072d?04/2011 at32uc3a3/a4 2. overview 2.1 block diagram figure 2-1. block diagram avr32uc cpu nexus class 2+ ocd instr interface data interface timer/counter 0/1 interrupt controller real time counter peripheral dma controller 256/128/64 kb flash hsb-pb bridge b hsb-pb bridge a memory interface s mm m m m s s s s s m external interrupt controller high speed bus matrix fast gpio general purpose ios 64 kb sram general purpose ios pa pb pc px a[2..0] b[2..0] clk[2..0] extint[7..0] scan[7..0] nmi gclk[3..0] xin32 xout32 xin0 xout0 pa pb pc px reset_n external bus interface (sdram, static memory, compact flash & nand flash) cas ras sda10 sdck sdcke sdwe ncs[5..0] nrd nwait nwe0 data[15..0] usb hs interface dma id vbof dmfs, dmhs 32 khz osc 115 khz rcsys osc0 pll0 usart3 serial peripheral interface 0/1 two-wire interface 0/1 dma dma dma rxd txd clk miso, mosi npcs[3..1] twck twd usart1 dma rxd txd clk rts, cts dsr, dtr, dcd, ri usart0 usart2 dma rxd txd clk rts, cts synchronous serial controller dma tx_clock, tx_frame_sync rx_data tx_data rx_clock, rx_frame_sync analog to digital converter dma ad[7..0] watchdog timer xin1 xout1 osc1 pll1 spck jtag interface mcko mdo[5..0] mseo[1..0] evti_n evto_n tck tdo tdi tms power manager reset controller addr[23..0] sleep controller clock controller clock generator flash controller configuration registers bus memory protection unit pb pb hsb hsb nwe1 nwe3 pba pbb npcs0 local bus interface audio bitstream dac dma data[1..0] datan[1..0] m multimedia card & memory stick interface clk cmd[1..0] data[15..0] dma s aes dma cfce1 cfce2 cfrw nandoe nandwe 32kb ram 32kb ram hram0/1 dpfs, dphs usb_vbias usb_vbus s s vddin vddcore gndcore dmaca 1v8 regulator twalm
5 32072d?04/2011 at32uc3a3/a4 2.2 configuration summary the table below lists all at32uc3a3/a4 memory and package configurations: table 2-1. configuration summary feature at32uc3a3256/128/64 at32uc3a4256/128/64 flash 256/128/64 kb sram 64 kb hsb ram 64 kb ebi full nand flash only gpio 110 70 external interrupts 8 twi 2 usart 4 peripheral dma channels 8 generic dma channels 4 spi 2 mci slots 2 mmc/sd slots 1 mmc/sd slot + 1 sd slot high speed usb 1 aes (s option) 1 ssc 1 audio bitstream dac 1 timer/counter channels 6 watchdog timer 1 real-time clock timer 1 power manager 1 oscillators pll 80-240 mhz (pll0/pll1) crystal oscillators 0. 4-20 mhz (osc0/osc1) crystal oscillator 32 khz (osc32k) rc oscillator 115 khz (rcsys) 10-bit adc number of channels 1 8 jtag 1 max frequency 66 mhz package lqfp144, tfbga144 vfbga100
6 32072d?04/2011 at32uc3a3/a4 3. package and pinout 3.1 package the device pins are multiplexed with peripheral fu nctions as described in the peripheral multi- plexing on i/o line section. figure 3-1. tfbga144 pinout (top view) 12 11 10 9 8 7 6 5 4 3 2 1 a b c d e f g h j k l m px40 pb00 pa28 pa27 pb03 pa29 pc02 pc04 pc05 dphs dmhs usb_vbus pa09 gndpll dmfs usb_vbias vddio pc03 pb04 vddio pb02 pa31 pb11 px10 px09 px35 gndio px37 px36 pb01 px16 px47 px19 pb08 pa30 px13 pa02 pb10 px12 pa10 pa08 gndcore dpfs pb06 pb07 pa11 pa26 vddin pa12 vddcore pa07 pa25 pa06 pa16 pa13 pa05 pa04 px53 vddio pb09 px15 px49 px48 gndio gndio px08 vddio px54 px38 px07 px06 px39 px50 px51 gndio gndio px05 px59 px00 px57 vddio pa17 pc01 vddio px58 px01 px56 px55 pa15 pa14 px02 px34 px04 px46 pc00 px52 px17 px44 gndio px03 px20 vddio px43 px18 gndio px45 px11 px14 px21 px24 px23 px41 px42 px22 pa23 pa01 pa00 pa03 pa24 vddio pb05 vddana pa22 pa21 pa19 reset_n tdo tms pa20 pa18 tck px29 gndio px27 vddin tdi gndana px28 px26 px25 px33 px30 px31 px32
7 32072d?04/2011 at32uc3a3/a4 figure 3-2. lqfp144 pinout usb_vbus 1 vddio 2 usb_vbias 3 gndio 4 dmhs 5 dphs 6 gndio 7 dmfs 8 dpfs 9 vddio 10 pb08 11 pc05 12 pc04 13 pa30 14 pa02 15 pb10 16 pb09 17 pc02 18 pc03 19 gndio 20 vddio 21 pb04 22 pa29 23 pb03 24 pb02 25 pa27 26 pb01 27 pa28 28 pa31 29 pb00 30 pb11 31 px16 32 px13 33 px12 34 px19 35 px40 36 px10 37 px35 38 px47 39 px15 40 px48 41 px53 42 px49 43 px36 44 px37 45 px54 46 gndio 47 vddio 48 px09 49 px08 50 px38 51 px39 52 px06 53 px07 54 px00 55 px59 56 px58 57 px05 58 px01 59 px04 60 px34 61 px02 62 px03 63 vddio 64 gndio 65 px44 66 px11 67 px14 68 px42 69 px45 70 px41 71 px22 72 tdi 108 tck 107 reset_n 106 tdo 105 tms 104 vddio 103 gndio 102 pa15 101 pa14 100 pc01 99 pc00 98 px31 97 px30 96 px33 95 px29 94 px32 93 px25 92 px28 91 px26 90 px27 89 px43 88 px52 87 px24 86 px23 85 px18 84 px17 83 gndio 82 vddio 81 px21 80 px55 79 px56 78 px51 77 px57 76 px50 75 px46 74 px20 73 pa21 109 pa22 110 pa23 111 pa24 112 pa20 113 pa19 114 pa18 115 pa17 116 gndana 117 vddana 118 pa25 119 pa26 120 pb05 121 pa00 122 pa01 123 pa05 124 pa03 125 pa04 126 pa06 127 pa16 128 pa13 129 vddio 130 gndio 131 pa12 132 pa07 133 pb06 134 pb07 135 pa11 136 pa08 137 pa10 138 pa09 139 gndcore 140 vddcore 141 vddin 142 vddin 143 gndpll 144
8 32072d?04/2011 at32uc3a3/a4 figure 3-3. vfbga100 pinout (top view) note: 1. those balls are physically connected to 2 gp ios. software must managed carrefully the gpio configuration to avoid electrical conflict 10 9 8 7 6 5 4 3 2 1 a b c d e f g h j k pa28 pa27 pb04 pa30 pc02 pc03 pc05 dphs dmhs usb_vbus gndpll dmfs dpfs pc04 vddio vddio pa29 pb02 pb01 pb00 pb11 pa31 gndio px10 px13 pb03 pb09 px16/ px53 (1) pb10 gndio usb_vbias pb08 pa09 pb06 pb07 pa10 pa11 vddin vddin pa06/ pa13 (1) vddcore pa04 pa08 gndcore pa03 px09 vddio pa16 gndio px07 gndio pa26/ pb05 (1) vddio px12 gndio px08 pa02/ px47 (1) vddio px06 px19/ px59 (1) px00 px30 pa12/ pa25 (1) pa23/ px46 (1) px01 px02 px05 px25 px31 tms pa22/ px20 (1) px21 gndio px04 px29 vddio pa15/ px45 (1) vddana px24 px26 px03 px15/ px32 (1) pc00/ px14 (1) pa14/ px11 (1) pc01 px27 px28 px23 pa00/ pa18 (1) pa01/ pa17 (1) pa05 gndana pa07/ pa19 (1) pa20/ px18 (1) tdo pa24/ px17 (1) reset_n tdi pa21/ px22 (1) tck
9 32072d?04/2011 at32uc3a3/a4 3.2 peripheral multiplexing on i/o lines 3.2.1 multiplexed signals each gpio line can be assigned to one of the peripheral functions. the following table describes the peripheral signals multiplexed to the gpio lines. table 3-1. gpio controller func tion multiplexing bga 144 qfp 144 bga 100 pin g p i o supply pin type (2) gpio function ab cd g11 122 g8 (1) pa00 0 vddio x3 usart0 - rts tc0 - clk1 spi1 - npcs[3] g12 123 g10 (1) pa01 1 vddio x1 usart0 - cts tc0 - a1 usart2 - rts d8 15 e1 (1) pa02 2 vddio x1 usart0 - clk tc0 - b1 spi0 - npcs[0] g10 125 f9 pa03 3 vddio x1 usart0 - rxd eic - extint[4] abdac - data[0] f9 126 e9 pa04 4 vddio x1 usart0 - txd eic - extint[5] abdac - datan[0] f10 124 g9 pa05 5 vddio x1 usart1 - rxd tc1 - clk0 usb - id f8 127 e8 (1) pa06 6 vddio x1 usart1 - txd tc1 - clk1 usb - vbof e10 133 h10 (1) pa07 7 vddio x1 spi0 - npcs[3] abdac - datan[0] usart1 - clk c11 137 f8 pa08 8 vddio x3 spi0 - spck abdac - data[0] tc1 - b1 b12 139 d8 pa09 9 vddio x2 spi0 - npcs[0] eic - extint[6] tc1 - a1 c12 138 c10 pa10 10 vddio x2 spi0 - mosi usb - vbof tc1 - b0 d10 136 c9 pa11 11 vddio x2 spi0 - miso usb - id tc1 - a2 e12 132 g7 (1) pa12 12 vddio x1 usart1 - cts spi0 - npcs[2] tc1 - a0 f11 129 e8 (1) pa13 13 vddio x1 usart1 - rts spi0 - npcs[1] eic - extint[7] j6 100 k7 (1) pa14 14 vddio x1 spi0 - npcs[1] twims0 - twalm twims1 - twck j7 101 j7 (1) pa15 15 vddio x1 mci - cmd[1] spi1 - spck twims1 - twd f12 128 e7 pa16 16 vddio x1 mci - data[11] spi1 - mosi tc1 - clk2 h7 116 g10 (1) pa17 17 vddana x1 mci - data[10] spi1 - npcs[1] adc - ad[7] k8 115 g8 (1) pa18 18 vddana x1 mci - data[9] spi1 - npcs[2] adc - ad[6] j8 114 h10 (1) pa19 19 vddana x1 mci - data[8] spi1 - miso adc - ad[5] j9 113 h9 (1) pa20 20 vddana x1 eic - nmi ssc - rx_frame_sync adc - ad[4] h9 109 k10 (1) pa21 21 vddana x1 adc - ad[0] eic - extint[0] usb - id h10 110 h6 (1) pa22 22 vddana x1 adc - ad[1] eic - extint[1] usb - vbof g8 111 g6 (1) pa23 23 vddana x1 adc - ad[2] eic - extint[2] abdac - data[1] g9 112 j10 (1) pa24 24 vddana x1 adc - ad[3] eic - extint[3] abdac - datan[1] e9 119 g7 (1) pa25 25 vddio x1 twims0 - twd twims1 - twalm usart1 - dcd d9 120 f7 (1) ) pa26 26 vddio x1 twims0 - twck usart2 - cts usart1 - dsr a4 26 a2 pa27 27 vddio x2 mci - clk ssc - rx_data usart3 - rts msi - sclk a3 28 a1 pa28 28 vddio x1 mci - cmd[0] ssc - rx_clock usart3 - cts msi - bs a6 23 b4 pa29 29 vddio x1 mci - data[0] usart3 - txd tc0 - clk0 msi - data[0] c7 14 a4 pa30 30 vddio x1 mci - data[1] usart3 - clk dmaca - dmaack[0] msi - data[1] b3 29 c2 pa31 31 vddio x1 mci - data[2] usart2 - rxd dmaca - dmarq[0] msi - data[2]
10 32072d?04/2011 at32uc3a3/a4 a2 30 b1 pb00 32 vddio x1 mci - data[3] usart2 - txd adc - trigger msi - data[3] c4 27 b2 pb01 33 vddio x1 mci - data[4] abdac - data[1] eic - scan[0] msi - ins b4 25 b3 pb02 34 vddio x1 mci - data[5] abdac - datan[1] eic - scan[1] a5 24 c4 pb03 35 vddio x1 mci - data[6] usart2 - clk eic - scan[2] b6 22 a3 pb04 36 vddio x1 mci - data[7] usart3 - rxd eic - scan[3] h12 121 f7 (1) pb05 37 vddio x3 usb - id tc0 - a0 eic - scan[4] d12 134 d7 pb06 38 vddio x1 usb - vbof tc0 - b0 eic - scan[5] d11 135 d6 pb07 39 vddio x3 spi1 - spck ssc - tx_clock eic - scan[6] c8 11 c6 pb08 40 vddio x2 spi1 - miso ssc - tx_data eic - scan[7] e7 17 c5 pb09 41 vddio x2 spi1 - npcs[0] ssc - rx_data ebi - ncs[4] d7 16 d5 pb10 42 vddio x2 spi1 - mosi ssc - rx_frame_sync ebi - ncs[5] b2 31 c1 pb11 43 vddio x1 usart1 - rxd ssc - tx_frame_sync pm - gclk[1] k5 98 k5 (1) pc00 45 vddio x1 h6 99 k6 pc01 46 vddio x1 a7 18 a5 pc02 47 vddio x1 b7 19 a6 pc03 48 vddio x1 a8 13 b7 pc04 49 vddio x1 a9 12 a7 pc05 50 vddio x1 g1 55 g4 px00 51 vddio x2 ebi - data[10] usart0 - rxd usart1 - ri h1 59 g2 px01 52 vddio x2 ebi - data[9] usart0 - txd usart1 - dtr j2 62 g3 px02 53 vddio x2 ebi - data[8] usart0 - cts pm - gclk[0] k1 63 j1 px03 54 vddio x2 ebi - data[7] usart0 - rts j1 60 h1 px04 55 vddio x2 ebi - data[6] usart1 - rxd g2 58 g1 px05 56 vddio x2 ebi - data[5] usart1 - txd f3 53 f3 px06 57 vddio x2 ebi - data[4] usart1 - cts f2 54 f4 px07 58 vddio x2 ebi - data[3] usart1 - rts d1 50 e3 px08 59 vddio x2 ebi - data[2] usart3 - rxd c1 49 e4 px09 60 vddio x2 ebi - data[1] usart3 - txd b1 37 d2 px10 61 vddio x2 ebi - data[0] usart2 - rxd l1 67 k7 (1) px11 62 vddio x2 ebi - nwe1 usart2 - txd d6 34 d1 px12 63 vddio x2 ebi - nwe0 usart2 - cts mci - clk c6 33 d3 px13 64 vddio x2 ebi - nrd usart2 - rts mci - clk m4 68 k5 (1) px14 65 vddio x2 ebi - ncs[1] tc0 - a0 e6 40 k4 (1) px15 66 vddio x2 ebi - addr[19] usart3 - rts tc0 - b0 c5 32 d4 (1) px16 67 vddio x2 ebi - addr[18] usart3 - cts tc0 - a1 k6 83 j10 (1) px17 68 vddio x2 ebi - addr[17] dmaca - dmarq[1] tc0 - b1 l6 84 h9 (1) px18 69 vddio x2 ebi - addr[16] dmaca - dmaack[1] tc0 - a2 d5 35 f1 (1) px19 70 vddio x2 ebi - addr[15] eic - scan[0] tc0 - b2 table 3-1. gpio controller func tion multiplexing bga 144 qfp 144 bga 100 pin g p i o supply pin type (2) gpio function ab cd
11 32072d?04/2011 at32uc3a3/a4 l4 73 h6 (1) px20 71 vddio x2 ebi - addr[14] eic - scan[1] tc0 - clk0 m5 80 h2 px21 72 vddio x2 ebi - addr[13] eic - scan[2] tc0 - clk1 m1 72 k10 (1) px22 73 vddio x2 ebi - addr[12] eic - scan[3] tc0 - clk2 m6 85 k1 px23 74 vddio x2 ebi - addr[11] eic - scan[4] ssc - tx_clock m7 86 j2 px24 75 vddio x2 ebi - addr[10] eic - scan[5] ssc - tx_data m8 92 h4 px25 76 vddio x2 ebi - addr[9] eic - scan[6] ssc - rx_data l9 90 j3 px26 77 vddio x2 ebi - addr[8] eic - scan[7] ssc - rx_frame_sync k9 89 k2 px27 78 vddio x2 ebi - addr[7] spi0 - miso ssc - tx_frame_sync l10 91 k3 px28 79 vddio x2 ebi - addr[6] spi0 - mosi ssc - rx_clock k11 94 j4 px29 80 vddio x2 ebi - addr[5] spi0 - spck m11 96 g5 px30 81 vddio x2 ebi - addr[4] spi0 - npcs[0] m10 97 h5 px31 82 vddio x2 ebi - addr[3] spi0 - npcs[1] m9 93 k4 (1) px32 83 vddio x2 ebi - addr[2] spi0 - npcs[2] m12 95 px33 84 vddio x2 ebi - addr[1] spi0 - npcs[3] j3 61 px34 85 vddio x2 ebi - addr[0] spi1 - miso pm - gclk[0] c2 38 px35 86 vddio x2 ebi - data[15] spi1 - mosi pm - gclk[1] d3 44 px36 87 vddio x2 ebi - data[14] spi1 - spck pm - gclk[2] d2 45 px37 88 vddio x2 ebi - data[13] spi1 - npcs[0] pm - gclk[3] e1 51 px38 89 vddio x2 ebi - data[12] spi1 - npcs[1] usart1 - dcd f1 52 px39 90 vddio x2 ebi - data[11] spi1 - npcs[2] usart1 - dsr a1 36 px40 91 vddio x2 mci - clk m2 71 px41 92 vddio x2 ebi - cas m3 69 px42 93 vddio x2 ebi - ras l7 88 px43 94 vddio x2 ebi - sda10 usart1 - ri k2 66 px44 95 vddio x2 ebi - sdwe usart1 - dtr l3 70 j7 (1) px45 96 vddio x3 ebi - sdck k4 74 g6 (1) px46 97 vddio x2 ebi - sdcke d4 39 e1 (1) px47 98 vddio x2 ebi - nandoe adc - trigger mci - data[11] f5 41 px48 99 vddio x2 ebi - addr[23] usb - vbof mci - data[10] f4 43 px49 100 vddio x2 ebi - cfrnw usb - id mci - data[9] g4 75 px50 101 vddio x2 ebi - cfce2 tc1 - b2 mci - data[8] g5 77 px51 102 vddio x2 ebi - cfce1 dmaca - dmaack[0] mci - data[15] k7 87 px52 103 vddio x2 ebi - ncs[3] dmaca - dmarq[0] mci - data[14] e4 42 d4 (1) px53 104 vddio x2 ebi - ncs[2] mci - data[13] e3 46 px54 105 vddio x2 ebi - nwait usart3 - txd mci - data[12] j5 79 px55 106 vddio x2 ebi - addr[22] eic - scan[3] usart2 - rxd j4 78 px56 107 vddio x2 ebi - addr[21] eic - scan[2] usart2 - txd table 3-1. gpio controller func tion multiplexing bga 144 qfp 144 bga 100 pin g p i o supply pin type (2) gpio function ab cd
12 32072d?04/2011 at32uc3a3/a4 note: 1. those balls are physically connected to 2 gpios. software must managed carrefully the gpio configuration to avoid electrical conflict. 2. refer to ?electrical characteristics? on page 977 for a description of the electrical properties of the pad types used. 3. gpio 44 is physically implemented in silicon but must be kept unused and configured in input mode. 3.2.2 peripheral functions each gpio line can be assigned to one of several peripheral functions. the following table describes how the various peripheral functions are selected. the last listed function has priority in case multiple functions are enabled on the same pin. 3.2.3 oscillator pinout the oscillators are not mapped to the normal gp io functions and their muxings are controlled by registers in the power mananger (pm). please refer to the pm chapter for more information about this. note: 1. this ball is physically connected to 2 gpios. software must managed carrefully the gpio con- figuration to avoid electrical conflict h4 76 px57 108 vddio x2 ebi - addr[20] eic - scan[1] usart3 - rxd h3 57 px58 109 vddio x2 ebi - ncs[0] eic - scan[0] usart3 - txd g3 56 f1 (1) px59 110 vddio x2 ebi - nandwe mci - cmd[1] table 3-1. gpio controller func tion multiplexing bga 144 qfp 144 bga 100 pin g p i o supply pin type (2) gpio function ab cd table 3-2. peripheral functions function description gpio controller function multiplexing gpio and gpio peripheral selection a to d nexus ocd aux port connections ocd trace system jtag port connections jtag debug port oscillators osc0, osc1, osc32 table 3-3. oscillator pinout tfbga144 qfp144 vfbga100 pin name oscillator pin a7 18 a5 pc02 xin0 b7 19 a6 pc03 xout0 a8 13 b7 pc04 xin1 a9 12 a7 pc05 xout1 k5 98 k5 (1) pc00 xin32 h6 99 k6 pc01 xout32
13 32072d?04/2011 at32uc3a3/a4 3.2.4 jtag port connections 3.2.5 nexus ocd aux port connections if the ocd trace system is enabled, the trace system will take control over a number of pins, irre- spective of the gpio configuration. three differents ocd trace pin mappings are possible, depending on the configuratio n of the ocd axs register. for details, see the avr32 uc tech- nical reference manual . table 3-4. jtag pinout tfbga144 qfp144 vfbga100 pin name jtag pin k12 107 k9 tck tck l12 108 k8 tdi tdi j11 105 j8 tdo tdo j10 104 h7 tms tms table 3-5. nexus ocd aux port connections pin axs=0 axs=1 axs=2 evti_n pb05 pa08 px00 mdo[5] pa00 px56 px06 mdo[4] pa01 px57 px05 mdo[3] pa03 px58 px04 mdo[2] pa16 pa24 px03 mdo[1] pa13 pa23 px02 mdo[0] pa12 pa22 px01 mseo[1] pa10 pa07 px08 mseo[0] pa11 px55 px07 mcko pb07 px00 pb09 evto_n pb06 pb06 pb06
14 32072d?04/2011 at32uc3a3/a4 3.3 signal descriptions the following table gives details on signal name classified by peripheral. table 3-6. signal description list signal name function type active level comments power vddio i/o power supply power 3.0 to 3.6v vddana analog power supply power 3.0 to 3.6v vddin voltage regulator input supply power 3.0 to 3.6v vddcore voltage regulator output for digital supply power output 1.65 to 1.95 v gndana analog ground ground gndio i/o ground ground gndcore digital ground ground gndpll pll ground ground clocks, oscillators, and pll?s xin0, xin1, xin32 crystal 0, 1, 32 input analog xout0, xout1, xout32 crystal 0, 1, 32 output analog jtag tck test clock input tdi test data in input tdo test data out output tms test mode select input auxiliary port - aux mcko trace data output clock output mdo[5:0] trace data output output mseo[1:0] trace frame control output evti_n event in input low evto_n event out output low power manager - pm gclk[3:0] generic clock pins output
15 32072d?04/2011 at32uc3a3/a4 reset_n reset pin input low dma controller - dmaca (optional) dmaack[1:0] dma acknowledge output dmarq[1:0] dma requests input external interrup t controller - eic extint[7:0] external interrupt pins input scan[7:0] keypad scan pins output nmi non-maskable interrupt pin input low general purpose input/output pin - gpioa, gpiob, gpioc, gpiox pa[31:0] parallel i/o controller gpio port a i/o pb[11:0] parallel i/o controller gpio port b i/o pc[5:0] parallel i/o controller gpio port c i/o px[59:0] parallel i/o controller gpio port x i/o external bus interface - ebi addr[23:0] address bus output cas column signal output low cfce1 compact flash 1 chip enable output low cfce2 compact flash 2 chip enable output low cfrnw compact flash read not write output data[15:0] data bus i/o nandoe nand flash output enable output low nandwe nand flash write enable output low ncs[5:0] chip select output low nrd read signal output low nwait external wait signal input low nwe0 write enable 0 output low nwe1 write enable 1 output low ras row signal output low table 3-6. signal description list signal name function type active level comments
16 32072d?04/2011 at32uc3a3/a4 sda10 sdram address 10 line output sdck sdram clock output sdcke sdram clock enable output sdwe sdram write enable output low multimedia card interface - mci clk multimedia card clock output cmd[1:0] multimedia card command i/o data[15:0] multimedia card data i/o memory stick interface - msi sclk memory stick clock output bs memory stick command i/o data[3:0] multimedia card data i/o serial peripheral in terface - spi0, spi1 miso master in slave out i/o mosi master out slave in i/o npcs[3:0] spi peripheral chip select i/o low spck clock output synchronous serial controller - ssc rx_clock ssc receive clock i/o rx_data ssc receive data input rx_frame_sync ssc receive frame sync i/o tx_clock ssc transmit clock i/o tx_data ssc transmit data output tx_frame_sync ssc transmit frame sync i/o timer/counter - tc0, tc1 a0 channel 0 line a i/o a1 channel 1 line a i/o a2 channel 2 line a i/o table 3-6. signal description list signal name function type active level comments
17 32072d?04/2011 at32uc3a3/a4 b0 channel 0 line b i/o b1 channel 1 line b i/o b2 channel 2 line b i/o clk0 channel 0 external clock input input clk1 channel 1 external clock input input clk2 channel 2 external clock input input two-wire interface - twi0, twi1 twck serial clock i/o twd serial data i/o twalm smbalert signal i/o universal synchronous asynchronous receiver transmitter - usart0, usart1, usart2, usart3 clk clock i/o cts clear to send input dcd data carrier detect only usart1 dsr data set ready only usart1 dtr data terminal ready only usart1 ri ring indicator only usart1 rts request to send output rxd receive data input txd transmit data output analog to digital converter - adc ad0 - ad7 analog input pins analog input audio bitstream dac (abdac) data0-data1 d/a data out output datan0-datan1 d/a data inverted out output universal serial bus device - usb dmfs usb full speed data - analog dpfs usb full speed data + analog table 3-6. signal description list signal name function type active level comments
18 32072d?04/2011 at32uc3a3/a4 dmhs usb high speed data - analog dphs usb high speed data + analog usb_vbias usb vbias reference analog connect to the ground through a 6810 ohms (+/- 1%) resistor in parallel with a 10pf capacitor. if usb hi-speed feature is not required, leave this pin unconnected to save power usb_vbus usb vbus signal output vbof usb vbus on/off bus power control port output id id pin fo the usb bus input table 3-6. signal description list signal name function type active level comments
19 32072d?04/2011 at32uc3a3/a4 3.4 i/o line considerations 3.4.1 jtag pins tms and tdi pins have pull-up resistors. tdo pin is an output, driven at up to vddio, and has no pull-up resistor. 3.4.2 reset_n pin the reset_n pin is a schmitt input and integrates a permanent pull-up resistor to vddio. as the product integrat es a power-on reset cell, the reset_n pin can be left unconnected in case no reset from the system needs to be applied to the product. 3.4.3 twi pins when these pins are used for twi, the pins are open-drain outputs with slew-rate limitation and inputs with inputs with spike filt ering. when used as gpio pins or used for other peripherals, the pins have the same characteristics as other gpio pins. 3.4.4 gpio pins all the i/o lines integrate a programmable pull-up resistor . programming of this pull-up resistor is performed independently for each i/o line through the i/o controller. after reset, i/o lines default as inputs with pull-up resistors disabled, except when indicated otherwise in the column ?reset state? of the i/o controller multiplexing tables.
20 32072d?04/2011 at32uc3a3/a4 3.5 power considerations 3.5.1 power supplies the at32uc3a3 has several types of power supply pins: ? vddio: powers i/o lines. voltage is 3.3v nominal ? vddana: powers the adc. voltage is 3.3v nominal ? vddin: input voltage for the voltage regulator. voltage is 3.3v nominal ? vddcore: output voltage from re gulator for filtering purpose an d provides the supply to the core, memories, and peripheral s. voltage is 1.8v nominal the ground pin gndcore is common to vddcore and vddin. the ground pin for vddana is gndana. the ground pins for vddio are gndio. refer to electrical characteristics chapter for power consumption on the various supply pins. 3.5.2 voltage regulator the at32uc3a3 embeds a voltage regulator that conv erts from 3.3v to 1.8v with a load of up to 100 ma. the regulator takes its input voltage from vddin, and supplies the output voltage on vddcore and powers the core, memories and peripherals. adequate output supply decoupling is mandat ory for vddcore to reduce ripple and avoid oscillations. the best way to achieve this is to use two capacitors in parallel between vddcore and gndcore: ? one external 470pf (or 1nf) npo capacitor (c out1 ) should be connected as close to the chip as possible. ? one external 2.2f (or 3.3f) x7r capacitor (c out2 ). adequate input supply decouplin g is mandatory for vddin in or der to improve startup stability and reduce source voltage drop. the input decoupling capacitor should be placed close to the chip, e.g., two capacitors can be used in parallel (1nf npo and 4.7f x7r). for decoupling recommendations for vddio and vddana please refer to the schematic checklist. 3.3v 1.8v vddin vddcore 1.8v regulator c in1 c out1 c out2 c in2
21 32072d?04/2011 at32uc3a3/a4 4. processor and architecture rev: 1.4.2.0 this chapter gives an overview of the avr32uc cpu. avr32uc is an implementation of the avr32 architecture. a summary of the programming model, instruction set, and mpu is pre- sented. for further details, see the avr32 architecture manual and the avr32uc technical reference manual . 4.1 features ? 32-bit load/store avr32a risc architecture ? 15 general-purpose 32-bit registers ? 32-bit stack pointer, program counter and link register reside in register file ? fully orthogonal instruction set ? privileged and unprivileged modes enabling efficient and secure operating systems ? innovative instruction set together with variable instruction length ensu ring industry leading code density ? dsp extention with saturating arithmetic, and a wide vari ety of multiply instructions ? 3-stage pipeline allows one instructio n per clock cycle for most instructions ? byte, halfword, word and double word memory access ? multiple interrupt priority levels ? mpu allows for operating s ystems with memory protection 4.2 avr32 architecture avr32 is a high-performance 32-bit risc microprocessor architecture, designed for cost-sensi- tive embedded applications, with particular emphasis on low power consumption and high code density. in addition, the instruction set architecture has been tuned to allow a variety of micro- architectures, enabling the avr32 to be implemented as low-, mid-, or high-performance processors. avr32 extends the avr family into the world of 32- and 64-bit applications. through a quantitative approach, a large set of industry recognized benchmarks has been com- piled and analyzed to achieve the best code density in its class. in addition to lowering the memory requirements, a compact code size also contributes to the core?s low power characteris- tics. the processor supports byte and halfword data types without penalty in code size and performance. memory load and store operations are provided for byte, halfword, word, and double word data with automatic sign- or zero extension of halfw ord and byte data. the c-compiler is closely linked to the architecture and is able to expl oit code optimization features, both for size and speed. in order to reduce code size to a minimum, so me instructions have multiple addressing modes. as an example, instructions with immediates often have a compact format with a smaller imme- diate, and an extended format with a larger immediate. in this way, the compiler is able to use the format giving the smallest code size. another feature of the instruction set is that frequently used instructions, like add, have a com- pact format with two operands as well as an extended format with three operands. the larger format increases performance, allowing an addition and a data move in the same instruction in a single cycle. load and store instructions have seve ral different formats in order to reduce code size and speed up execution.
22 32072d?04/2011 at32uc3a3/a4 the register file is organized as sixteen 32-bi t registers and includes the program counter, the link register, and the stack pointer. in addition, register r12 is designed to hold return values from function calls and is used im plicitly by some instructions. 4.3 the avr32uc cpu the avr32uc cpu targets low- and mediu m-performance applications, and provides an advanced ocd system, no caches, and a memory protection unit (mpu). java acceleration hardware is not implemented. avr32uc provides three memory interfaces, one high speed bus master for instruction fetch, one high speed bus master for data access, an d one high speed bus slave interface allowing other bus masters to access data rams internal to the cpu. keeping data rams internal to the cpu allows fast access to the rams, reduces latency, and guarantees deterministic timing. also, power consumption is reduced by not needing a full high speed bus access for memory accesses. a dedicated data ram interface is prov ided for communicating with the internal data rams. a local bus interface is provided for connecting the cpu to device-specific high-speed systems, such as floating-point units and fast gpio ports. this local bus has to be enabled by writing the locen bit in the cpucr system re gister. the local bus is able to transfe r data between the cpu and the local bus slave in a single clock cycle. the local bus has a dedicated memory range allocated to it, and data transfers are performed using regular load and store instructions. details on which devices that are mapped into the local bus space is given in the memories chapter of this data sheet. figure 4-1 on page 23 displays the contents of avr32uc.
23 32072d?04/2011 at32uc3a3/a4 figure 4-1. overview of the avr32uc cpu 4.3.1 pipeline overview avr32uc has three pipeline stages, instruction fetch (if), instruction decode (id), and instruc- tion execute (ex). the ex stage is split into three parallel subsections, one arithmetic/logic (alu) section, one multiply (mul) sect ion, and one load/store (ls) section. instructions are issued and complete in order. certain operations require several clock cycles to complete, and in this case, the instruction resides in the id and ex stages for the required num- ber of clock cycles. since there is only three pipeline stages, no inte rnal data forwarding is required, and no data dependencies can arise in the pipeline. figure 4-2 on page 24 shows an overview of the avr32uc pipeline stages. avr32uc cpu pipeline instruction memory controller high speed bus master mpu high speed bus high speed bus ocd system ocd interface interrupt controller interface high speed bus slave high speed bus data ram interface high speed bus master power/ reset control reset interface cpu local bus master cpu local bus data memory controller
24 32072d?04/2011 at32uc3a3/a4 figure 4-2. the avr32uc pipeline 4.3.2 avr32a microarchitecture compliance avr32uc implements an avr32a microarchitecture. the avr32a microarchitecture is tar- geted at cost-sensitive, lower-end applications like smaller microcontrollers. this microarchitecture does not provide dedicated hard ware registers for shadowing of register file registers in interrupt contexts. additionally, it does not provide hardware registers for the return address registers and return status registers. instead, all this information is stored on the system stack. this saves chip area at the expense of slower interrupt handling. upon interrupt initiation, registers r8-r12 are automatically pushed to the system stack. these registers are pushed regardless of the priority level of the pending interrupt. the return address and status register are also automatically pushed to stack. the interrupt handler can therefore use r8-r12 freely. upon interrupt completion, the old r8-r12 registers and status register are restored, and execution continues at the return address stored popped from stack. the stack is also used to store the status register and return address for exceptions and scall . executing the rete or rets instruction at the completion of an exception or system call will pop this status register and continue execution at the popped return address. 4.3.3 java support avr32uc does not provide java hardware acceleration. 4.3.4 memory protection the mpu allows the user to check all memory accesses for privilege violations. if an access is attempted to an illegal memory address, the access is aborted and an exception is taken. the mpu in avr32uc is specified in t he avr32uc technical reference manual. 4.3.5 unaligned reference handling avr32uc does not support unaligned accesses, except for doubleword accesses. avr32uc is able to perform word-aligned st.d and ld.d . any other unaligned memory access will cause an address exception. doubleword -sized accesses with word-align ed pointers will automatically be performed as two word-sized accesses. if id alu mul regfile write prefetch unit decode unit alu unit multiply unit load-store unit ls regfile read
25 32072d?04/2011 at32uc3a3/a4 the following table shows the instructions with support for unaligned addresses. all other instructions requir e aligned addresses. 4.3.6 unimplemented instructions the following instructions are unimplemented in avr32uc, and will cause an unimplemented instruction exception if executed: ? all simd instructions ? all coprocessor instructions if no coprocessors are present ? retj, incjosp, popjc, pushjc ? tlbr, tlbs, tlbw ? cache 4.3.7 cpu and architecture revision three major revisions of the avr32uc cpu currently exist. the architecture revision field in the config0 system register identifies which architecture revision is implemented in a specific device. avr32uc cpu revision 3 is fully backward-compatibl e with revisions 1 and 2, ie. code compiled for revision 1 or 2 is binary-compatible with revision 3 cpus. table 4-1. instructions with una ligned reference support instruction supported alignment ld.d word st.d word
26 32072d?04/2011 at32uc3a3/a4 4.4 programming model 4.4.1 register file configuration the avr32uc register file is shown below. figure 4-3. the avr32uc register file 4.4.2 status register configuration the status register (sr) is split into two halfwords, one upper and one lower, see figure 4-4 on page 26 and figure 4-5 on page 27 . the lower word contains the c, z, n, v, and q condition code flags and the r, t, and l bits, while the upper halfword contains information about the mode and state the processor executes in. refer to the avr32 architecture manual for details. figure 4-4. the status register high halfword application bit 0 supervisor bit 31 pc sr int0pc fintpc int1pc smpc r7 r5 r6 r4 r3 r1 r2 r0 bit 0 bit 31 pc sr r12 int0pc fintpc int1pc smpc r7 r5 r6 r4 r11 r9 r10 r8 r3 r1 r2 r0 int0 sp_app sp_sys r12 r11 r9 r10 r8 exception nmi int1 int2 int3 lr lr bit 0 bit 31 pc sr r12 int0pc fintpc int1pc smpc r7 r5 r6 r4 r11 r9 r10 r8 r3 r1 r2 r0 sp_sys lr bit 0 bit 31 pc sr r12 int0pc fintpc int1pc smpc r7 r5 r6 r4 r11 r9 r10 r8 r3 r1 r2 r0 sp_sys lr bit 0 bit 31 pc sr r12 int0pc fintpc int1pc smpc r7 r5 r6 r4 r11 r9 r10 r8 r3 r1 r2 r0 sp_sys lr bit 0 bit 31 pc sr r12 int0pc fintpc int1pc smpc r7 r5 r6 r4 r11 r9 r10 r8 r3 r1 r2 r0 sp_sys lr bit 0 bit 31 pc sr r12 int0pc fintpc int1pc smpc r7 r5 r6 r4 r11 r9 r10 r8 r3 r1 r2 r0 sp_sys lr bit 0 bit 31 pc sr r12 int0pc fintpc int1pc smpc r7 r5 r6 r4 r11 r9 r10 r8 r3 r1 r2 r0 sp_sys lr secure bit 0 bit 31 pc sr r12 int0pc fintpc int1pc smpc r7 r5 r6 r4 r11 r9 r10 r8 r3 r1 r2 r0 sp_sec lr ss_status ss_adrf ss_adrr ss_adr0 ss_adr1 ss_sp_sys ss_sp_app ss_rar ss_rsr bit 31 0 0 0 bit 16 interrupt level 0 mask interrupt level 1 mask interrupt level 3 mask interrupt level 2 mask 1 0 0 0 0 1 1 0 0 0 0 0 0 fe i0m gm m1 - d m0 em i2m dm - m2 lc 1 initial value bit name i1m mode bit 0 mode bit 1 - mode bit 2 reserved debug state - i3m reserved exception mask global interrupt mask debug state mask -
27 32072d?04/2011 at32uc3a3/a4 figure 4-5. the status register low halfword 4.4.3 processor states 4.4.3.1 normal risc state the avr32 processor supports several diff erent execution contexts as shown in table 4-2 on page 27 . mode changes can be made under software control, or can be caused by external interrupts or exception processing. a mode can be interrupted by a higher priority mode, but never by one with lower priority. nested exceptions can be supported with a minimal software overhead. when running an operating system on the avr32, user processes will typically execute in the application mode. the programs executed in this mode are restricted from executing certain instructions. furthermore, most system registers together with the upper halfword of the status register cannot be accessed. protected memory areas are also not available. all other operating modes are privileged and are collectively called system modes. they have full access to all priv- ileged and unprivileged re sources. after a reset, the proc essor will be in su pervisor mode. 4.4.3.2 debug state the avr32 can be set in a debug state, which allows implementation of software monitor rou- tines that can read out and alter system information for use during application development. this implies that all system and application regist ers, including the status registers and program counters, are accessible in debug state. th e privileged instructions are also available. bit 15 bit 0 reserved carry zero sign 0 0 0 0 0 0 0 0 0 0 0 0 0 0 - - - - t - bit name initial value 0 0 l q v n z c - overflow saturation - - - lock reserved scratch table 4-2. overview of execution modes, thei r priorities and privilege levels. priority mode securi ty description 1 non maskable interrupt privileged non maskable high priority interrupt mode 2 exception privileged execute exceptions 3 interrupt 3 privileged general purpose interrupt mode 4 interrupt 2 privileged general purpose interrupt mode 5 interrupt 1 privileged general purpose interrupt mode 6 interrupt 0 privileged general purpose interrupt mode n/a supervisor privileged runs supervisor calls n/a application unprivileged normal program execution mode
28 32072d?04/2011 at32uc3a3/a4 all interrupt levels are by default disabled when debug state is entered, but they can individually be switched on by the monitor routine by clearing the respective mask bit in the status register. debug state can be entered as described in the avr32uc technical reference manual . debug state is exited by the retd instruction. 4.4.4 system registers the system registers are placed outside of the virtual memory space, and are only accessible using the privileged mfsr and mtsr instructions. the table below lis ts the system registers speci- fied in the avr32 architecture, some of which are unused in avr32uc. the programmer is responsible for maintaining correct sequen cing of any instructions following a mtsr instruction. for detail on the system registers, refer to the avr32uc technical reference manual . table 4-3. system registers reg # address name function 0 0 sr status register 1 4 evba exception vector base address 2 8 acba application call base address 3 12 cpucr cpu control register 4 16 ecr exception cause register 5 20 rsr_sup unused in avr32uc 6 24 rsr_int0 unused in avr32uc 7 28 rsr_int1 unused in avr32uc 8 32 rsr_int2 unused in avr32uc 9 36 rsr_int3 unused in avr32uc 10 40 rsr_ex unused in avr32uc 11 44 rsr_nmi unused in avr32uc 12 48 rsr_dbg return status register for debug mode 13 52 rar_sup unused in avr32uc 14 56 rar_int0 unused in avr32uc 15 60 rar_int1 unused in avr32uc 16 64 rar_int2 unused in avr32uc 17 68 rar_int3 unused in avr32uc 18 72 rar_ex unused in avr32uc 19 76 rar_nmi unused in avr32uc 20 80 rar_dbg return address register for debug mode 21 84 jecr unused in avr32uc 22 88 josp unused in avr32uc 23 92 java_lv0 unused in avr32uc 24 96 java_lv1 unused in avr32uc 25 100 java_lv2 unused in avr32uc
29 32072d?04/2011 at32uc3a3/a4 26 104 java_lv3 unused in avr32uc 27 108 java_lv4 unused in avr32uc 28 112 java_lv5 unused in avr32uc 29 116 java_lv6 unused in avr32uc 30 120 java_lv7 unused in avr32uc 31 124 jtba unused in avr32uc 32 128 jbcr unused in avr32uc 33-63 132-252 reserved reserved for future use 64 256 config0 configuration register 0 65 260 config1 configuration register 1 66 264 count cycle counter register 67 268 compare compare register 68 272 tlbehi unused in avr32uc 69 276 tlbelo unused in avr32uc 70 280 ptbr unused in avr32uc 71 284 tlbear unused in avr32uc 72 288 mmucr unused in avr32uc 73 292 tlbarlo unused in avr32uc 74 296 tlbarhi unused in avr32uc 75 300 pccnt unused in avr32uc 76 304 pcnt0 unused in avr32uc 77 308 pcnt1 unused in avr32uc 78 312 pccr unused in avr32uc 79 316 bear bus error address register 80 320 mpuar0 mpu address register region 0 81 324 mpuar1 mpu address register region 1 82 328 mpuar2 mpu address register region 2 83 332 mpuar3 mpu address register region 3 84 336 mpuar4 mpu address register region 4 85 340 mpuar5 mpu address register region 5 86 344 mpuar6 mpu address register region 6 87 348 mpuar7 mpu address register region 7 88 352 mpupsr0 mpu privilege select register region 0 89 356 mpupsr1 mpu privilege select register region 1 90 360 mpupsr2 mpu privilege select register region 2 91 364 mpupsr3 mpu privilege select register region 3 table 4-3. system registers (continued) reg # address name function
30 32072d?04/2011 at32uc3a3/a4 4.5 exceptions and interrupts avr32uc incorporates a powerful exception handling scheme. the different exception sources, like illegal op-code and external interrupt requests, have different priority levels, ensuring a well- defined behavior when multiple exceptions ar e received simultaneously. additionally, pending exceptions of a higher priority class may preempt handling of ongoing exceptions of a lower pri- ority class. when an event occurs, the execution of the instruction stream is halted, and execution control is passed to an event handler at an address specified in table 4-4 on page 33 . most of the han- dlers are placed sequentially in the code space starting at the address specified by evba, with four bytes between each handler. this gives am ple space for a jump instruction to be placed there, jumping to the event rout ine itself. a few critical handle rs have larger spacing between them, allowing the entire event routine to be placed directly at the address specified by the evba-relative offset generated by hardware. all external interrupt sources have autovectored interrupt service routine (isr) addresses. this allows the interrupt controller to directly specify the isr address as an address relative to evba. the autovector offset has 14 address bits, giv- ing an offset of maximum 16384 bytes. the target address of the event handler is calculated as (evba | event_handler_offset), not (evba + even t_handler_offset), so evba and exception code segments must be set up appropriately. th e same mechanisms are used to service all dif- ferent types of events, including external in terrupt requests, yielding a uniform event handling scheme. an interrupt controller does the priority handling of the external interrupts and provides the autovector offset to the cpu. 4.5.1 system stack issues event handling in avr32uc uses the system stack pointed to by the system stack pointer, sp_sys, for pushing and popping r8 -r12, lr, status register, and return ad dress. since event code may be timing-critical, sp_sys should point to memory addresses in the iram section, since the timing of accesses to this memory section is both fast and deterministic. 92 368 mpupsr4 mpu privilege select register region 4 93 372 mpupsr5 mpu privilege select register region 5 94 376 mpupsr6 mpu privilege select register region 6 95 380 mpupsr7 mpu privilege select register region 7 96 384 mpucra unused in this version of avr32uc 97 388 mpucrb unused in this version of avr32uc 98 392 mpubra unused in this version of avr32uc 99 396 mpubrb unused in this version of avr32uc 100 400 mpuapra mpu access permission register a 101 404 mpuaprb mpu access permission register b 102 408 mpucr mpu control register 103-191 448-764 reserved reserved for future use 192-255 768-1020 impl implementation defined table 4-3. system registers (continued) reg # address name function
31 32072d?04/2011 at32uc3a3/a4 the user must also make sure that the system stack is large enough so that any event is able to push the required registers to stack. if the system stack is full, and an event occurs, the system will enter an undefined state. 4.5.2 exceptions and interrupt requests when an event other than scall or debug request is received by the core, the following actions are performed atomically: 1. the pending event will not be acce pted if it is masked. the i3 m, i2m, i1m, i0m, em, and gm bits in the status register are used to mask different events. not all events can be masked. a few critical events (nmi, unreco verable exception, tlb multiple hit, and bus error) can not be masked. when an event is accepted, hardware automatically sets the mask bits corresponding to all sources with equal or lower priority. this inhibits acceptance of other events of the same or lower priority, except for the critical events listed above. software may choose to clear some or all of these bits after saving the necessary state if other priority schemes are desired. it is the event source?s respons- ability to ensure that their events are left pending until accepted by the cpu. 2. when a request is accepted, the status register and program counter of the current context is stored to the system stack. if the event is an int0, int1, int2, or int3, reg- isters r8-r12 and lr are also automatically stored to stack. storing the status register ensures that the core is returned to the previous execution mode when the current event handling is completed. when exceptions occur, both the em and gm bits are set, and the application may manually enable nested exceptions if desired by clear- ing the appropriate bit. each exception handler has a dedicated handler address, and this address uniquely identifies the exception source. 3. the mode bits are set to reflect the priority of the accepted event, and the correct regis- ter file bank is selected. the address of the event handler, as shown in table 4-4, is loaded into the program counter. the execution of the event handler routine then continues from the effective address calculated. the rete instruction signals the end of the event. when encountered, the return status register and return address register are popped from the system stack and restored to the status reg- ister and program counter. if the rete instruction returns from int0, int1, int2, or int3, registers r8-r12 and lr are also popped from the system stack. the restored status register contains information allowing the core to resume operation in the previous execution mode. this concludes the event handling. 4.5.3 supervisor calls the avr32 instruction set provides a supervisor mode call instruction. the scall instruction is designed so that privileged routines can be called from any context. this facilitates sharing of code between different execution modes. the scall mechanism is designed so that a minimal execution cycle overhead is experienced when performing supervisor routine calls from time- critical event handlers. the scall instruction behaves differently depending on which mode it is called from. the behav- iour is detailed in the instruction se t reference. in order to allow the scall routine to return to the correct context, a return from supervisor call instruction, rets , is implemented. in the avr32uc cpu, scall and rets uses the system stack to store the return address and the status register. 4.5.4 debug requests the avr32 architecture defines a dedicated debug mode. when a debug request is received by the core, debug mode is entered. entry into debug mode can be masked by the dm bit in the
32 32072d?04/2011 at32uc3a3/a4 status register. upon entry into debug mode, hardware sets the sr[d] bit and jumps to the debug exception handler. by default, debug mode executes in the exception context, but with dedicated return address register and return status register. these dedicated registers remove the need for storing this data to the system stack, t hereby improving debuggability. the mode bits in the status register can freely be manipulated in debug mode, to observe registers in all contexts, while retaining full privileges. debug mode is exited by executing the retd instruction. this return s to the previous context. 4.5.5 entry points for events several different event handler entry points exists. in avr32uc, the reset address is 0x8000_0000. this places the reset address in the boot flash memory area. tlb miss exceptions and scall have a dedicated space relative to evba where their event han- dler can be placed. this speeds up execution by removing the need for a jump instruction placed at the program address jumped to by the event hardware. all other exceptions have a dedicated event routine entry point located relative to evba. the handler routine address identifies the exception source directly. avr32uc uses the itlb and dtlb protection exc eptions to signal a mp u protection violation. itlb and dtlb miss exceptions are used to signal that an access address did not map to any of the entries in the mpu. tlb multiple hit exception indicates that an access address did map to multiple tlb entries, signalling an error. all external interrupt r equests have entry point s located at an offset relative to evba. this autovector offset is specified by an external interrupt controller. the programmer must make sure that none of the autovector offsets interfer e with the placement of other code. the autovec- tor offset has 14 address bits, giving an offset of maximum 16384 bytes. special considerations should be made when loading evba with a po inter. due to security con- siderations, the event handlers should be located in non-writeable flash memory, or optionally in a privileged memory protection region if an mpu is present. if several events occur on the same instruction, they are handled in a prioritized way. the priority ordering is presented in table 4-4. if events occur on several instructions at different locations in the pipeline, the events on the oldest instruction are always handled before any events on any younger instruction, even if the younger instructi on has events of higher priority than the oldest instruction. an instruction b is younger than an in struction a if it was sent down the pipeline later than a. the addresses and priority of simultaneous events are shown in table 4-4. some of the excep- tions are unused in avr32uc since it has no mmu, coprocessor interface, or floating-point unit.
33 32072d?04/2011 at32uc3a3/a4 table 4-4. priority and handler addresses for events priority handler address name event source stored return address 1 0x8000_0000 reset external input undefined 2 provided by ocd system ocd stop cpu ocd system first non-compl eted instruction 3 evba+0x00 unrecoverable exception int ernal pc of offending instruction 4 evba+0x04 tlb multiple hit mpu 5 evba+0x08 bus error data fetch data bu s first non-completed instruction 6 evba+0x0c bus error instruction fetch dat a bus first non-completed instruction 7 evba+0x10 nmi external input first non-completed instruction 8 autovectored interrupt 3 request external input first non-completed instruction 9 autovectored interrupt 2 request external input first non-completed instruction 10 autovectored interrupt 1 request external input first non-completed instruction 11 autovectored interrupt 0 request external input first non-completed instruction 12 evba+0x14 instruction address cp u pc of offending instruction 13 evba+0x50 itlb miss mpu 14 evba+0x18 itlb protection mpu pc of offending instruction 15 evba+0x1c breakpoint ocd system firs t non-completed instruction 16 evba+0x20 illegal opcode instructio n pc of offending instruction 17 evba+0x24 unimplemented instruction instr uction pc of offending instruction 18 evba+0x28 privilege violation instruc tion pc of offending instruction 19 evba+0x2c floating-point unused 20 evba+0x30 coprocessor absent instruct ion pc of offending instruction 21 evba+0x100 supervisor call instru ction pc(supervisor call) +2 22 evba+0x34 data address (read) cp u pc of offending instruction 23 evba+0x38 data address (write) cpu pc of offending instruction 24 evba+0x60 dtlb miss (read) mpu 25 evba+0x70 dtlb miss (write) mpu 26 evba+0x3c dtlb protection (read) mpu pc of offending instruction 27 evba+0x40 dtlb protection (write) m pu pc of offending instruction 28 evba+0x44 dtlb modified unused
34 32072d?04/2011 at32uc3a3/a4 4.6 module configuration all at32uc3a3 parts implement the cpu and architecture revision 2.
35 32072d?04/2011 at32uc3a3/a4 5. memories 5.1 embedded memories ? internal high-speed flash ? 256kbytes (at32uc3a3256/s) ? 128kbytes (at32uc3a3128/s) ? 64kbytes (at32uc3a364/s) ? 0 wait state access at up to 36mhz in worst case conditions ? 1 wait state access at up to 66mhz in worst case conditions ? pipelined flash architecture, allowing burst r eads from sequential flas h locations, hiding penalty of 1 wait state access ? pipelined flash architecture typically reduces the cycle penalty of 1 wait state operation to only 15% compared to 0 wait state operation ? 100 000 write cycles, 15-year data retention capability ? sector lock capabilities, bootlo ader protection, security bit ? 32 fuses, erased during chip erase ? user page for data to be preserved during chip erase ? internal high-speed sram ? 64kbytes, single-cycle access at full speed on cpu local bus and accessible through the high speed bud (hsb) matrix ? 2x32kbytes, accessible independently th rough the high spee d bud (hsb) matrix 5.2 physical memory map the system bus is implemented as a bus matrix . all system bus addresses are fixed, and they are never remapped in any way, not even in boot. note that avr32 uc cpu uses unsegmented translation, as described in the avr32uc techni- cal architecture manual. the 32-bit physical address s pace is mapped as follows: table 5-1. at32uc3a3a4 physical memory map device start address size size size at32uc3a3256s at32uc3a3256 at32uc3a4256s at32uc3a4256 at32uc3a3128s at32uc3a3128 at32uc3a4128s at32uc3a4128 at32uc3a364s at32uc3a364 at32uc3a464s at32uc3a464 embedded cpu sram 0x00000000 64kbyte 64kbyte 64kbyte embedded flash 0x80000000 256kbyte 128kbyte 64kbyte ebi sram cs0 0xc0000000 16mbyte 16mbyte 16mbyte ebi sram cs2 0xc8000000 16mbyte 16mbyte 16mbyte ebi sram cs3 0xcc000000 16mbyte 16mbyte 16mbyte ebi sram cs4 0xd8000000 16mbyte 16mbyte 16mbyte ebi sram cs5 0xdc000000 16mbyte 16mbyte 16mbyte ebi sram cs1 /sdram cs0 0xd0000000 128mbyte 128mbyte 128mbyte usb data 0xe0000000 64kbyte 64kbyte 64kbyte
36 32072d?04/2011 at32uc3a3/a4 5.3 peripheral address map hramc0 0xff000000 32kbyte 32kbyte 32kbyte hramc1 0xff008000 32kbyte 32kbyte 32kbyte hsb-pb bridge a 0xffff0000 64kbyte 64kbyte 64kbyte hsb-pb bridge b 0xfffe0000 64kbyte 64kbyte 64kbyte table 5-1. at32uc3a3a4 physical memory map device start address size size size at32uc3a3256s at32uc3a3256 at32uc3a4256s at32uc3a4256 at32uc3a3128s at32uc3a3128 at32uc3a4128s at32uc3a4128 at32uc3a364s at32uc3a364 at32uc3a464s at32uc3a464 table 5-2. peripheral address mapping address peripheral name 0xff100000 dmaca dma controller - dmaca 0xfffd0000 aes advanced encryption standard - aes 0xfffe0000 usb usb 2.0 device and host interface - usb 0xfffe1000 hmatrix hsb matrix - hmatrix 0xfffe1400 flashc flash controller - flashc 0xfffe1c00 smc static memory controller - smc 0xfffe2000 sdramc sdram controller - sdramc 0xfffe2400 ecchrs error code corrector hamming and reed solomon - ecchrs 0xfffe2800 busmon bus monitor module - busmon 0xfffe4000 mci mulitmedia card interface - mci 0xfffe8000 msi memory stick interface - msi 0xffff0000 pdca peripheral dma controller - pdca 0xffff0800 intc interrupt controller - intc
37 32072d?04/2011 at32uc3a3/a4 0xffff0c00 pm power manager - pm 0xffff0d00 rtc real time counter - rtc 0xffff0d30 wdt watchdog timer - wdt 0xffff0d80 eic external interrupt controller - eic 0xffff1000 gpio general purpose input/ output controller - gpio 0xffff1400 usart0 universal synchronous/asynchronous receiver/transmitter - usart0 0xffff1800 usart1 universal synchronous/asynchronous receiver/transmitter - usart1 0xffff1c00 usart2 universal synchronous/asynchronous receiver/transmitter - usart2 0xffff2000 usart3 universal synchronous/asynchronous receiver/transmitter - usart3 0xffff2400 spi0 serial peripheral interface - spi0 0xffff2800 spi1 serial peripheral interface - spi1 0xffff2c00 twim0 two-wire master interface - twim0 0xffff3000 twim1 two-wire master interface - twim1 0xffff3400 ssc synchronous serial controller - ssc 0xffff3800 tc0 timer/counter - tc0 0xffff3c00 adc analog to digital converter - adc 0xffff4000 abdac audio bitstream dac - abdac 0xffff4400 tc1 timer/counter - tc1 table 5-2. peripheral address mapping
38 32072d?04/2011 at32uc3a3/a4 5.4 cpu local bus mapping some of the registers in the gpio module are mapped onto the cpu local bus, in addition to being mapped on the peripheral bus. these registers can therefore be reached both by accesses on the peripheral bus, and by accesses on the local bus. mapping these registers on the local bus allows cycle-deterministic toggling of gpio pins since the cpu and gpio are the only modules connected to this bus. also, since the local bus runs at cpu speed, one write or read operation can be pe rformed per clock cycle to the local bus- mapped gpio registers. the following gpio registers are mapped on the local bus: 0xffff5000 twis0 two-wire slave interface - twis0 0xffff5400 twis1 two-wire slave interface - twis1 table 5-2. peripheral address mapping table 5-3. local bus mapped gpio registers port register mode local bus address access 0 output driver enable register (oder) write 0x40000040 write-only set 0x40000044 write-only clear 0x40000048 write-only toggle 0x4000004c write-only output value register (ovr) write 0x40000050 write-only set 0x40000054 write-only clear 0x40000058 write-only toggle 0x4000005c write-only pin value register (pvr) - 0x40000060 read-only 1 output driver enable register (oder) write 0x40000140 write-only set 0x40000144 write-only clear 0x40000148 write-only toggle 0x4000014c write-only output value register (ovr) write 0x40000150 write-only set 0x40000154 write-only clear 0x40000158 write-only toggle 0x4000015c write-only pin value register (pvr) - 0x40000160 read-only
39 32072d?04/2011 at32uc3a3/a4 2 output driver enable register (oder) write 0x40000240 write-only set 0x40000244 write-only clear 0x40000248 write-only toggle 0x4000024c write-only output value register (ovr) write 0x40000250 write-only set 0x40000254 write-only clear 0x40000258 write-only toggle 0x4000025c write-only pin value register (pvr) - 0x40000260 read-only 3 output driver enable register (oder) write 0x40000340 write-only set 0x40000344 write-only clear 0x40000348 write-only toggle 0x4000034c write-only output value register (ovr) write 0x40000350 write-only set 0x40000354 write-only clear 0x40000358 write-only toggle 0x4000035c write-only pin value register (pvr) - 0x40000360 read-only table 5-3. local bus mapped gpio registers port register mode local bus address access
40 32072d?04/2011 at32uc3a3/a4 6. boot sequence this chapter summarizes the boot sequence of the at32uc3a3/a4. the behavior after power- up is controlled by the power manager. for specific details, refer to section 7. ?power manager (pm)? on page 41 . 6.1 starting of clocks after power-up, the device will be held in a reset state by the power-on reset circuitry, until the power has stabilized throughout the device. once the power has stabilized, the device will use the internal rc oscilla tor as clock source. on system start-up, the plls are disabled. all clocks to all modules are running. no clocks have a divided frequency, all parts of the system receives a clock with the same frequency as the internal rc oscillator. 6.2 fetching of initial instructions after reset has been released, the avr32 uc cpu starts fetching instructions from the reset address, which is 0x8000_0000. this address points to the first address in the internal flash. the internal flash uses vddio voltage during read and write operations. it is recommended to use the bod33 to monitor this voltage and make sure the vddio is above the minimum level (3.0v). the code read from the internal flash is free to configure the system to use for example the plls, to divide the frequency of the clock routed to some of the peripherals, and to gate the clocks to unused peripherals. when powering up the device, there may be a delay before the voltage has stabilized, depend- ing on the rise time of the supply used. the cpu can start executing code as soon as the supply is above the por threshold, and before the supply is stable. before switching to a high-speed clock source, the user should use the bod to make sure the vddcore is above the minimum- level (1.62v).
41 32072d?04/2011 at32uc3a3/a4 7. power manager (pm) rev: 2.3.1.0 7.1 features ? controls integrated oscillators and plls ? generates clocks and resets for digital logic ? supports 2 crystal oscillators 0.4-20mhz ? supports 2 plls 40-240mhz ? supports 32khz ultra-low power oscillator ? integrated low-power rc oscillator ? on-the fly frequency change of cpu, hsb, pba, and pbb clocks ? sleep modes allow simple disabling of logic clocks, plls, and oscillators ? module-level clock gating through maskable peripheral clocks ? wake-up from internal or external interrupts ? generic clocks with wide frequency range provided ? automatic identificat ion of reset sources ? controls brownout detector (bod and bod33), rc oscillator, and bandgap voltage reference through control and calibration registers 7.2 overview the power manager (pm) controls the oscillators and plls, and generates the clocks and resets in the device. the pm cont rols two fast crystal oscillators , as well as two plls, which can multiply the clock from either oscillator to provide higher frequencies. additionally, a low-power 32khz oscillator is used to generate the real-time counter cl ock for high accura cy real-time mea- surements. the pm also contains a low-power rc oscillator with fa st start-up time, which can be used to clock the digital logic. the provided clocks are divided into synchr onous and generic clocks. the synchronous clocks are used to clock the main digital logic in the device, namely the cpu, and the modules and peripherals connected to the hsb, pba, and pbb buses. the generic clocks are asynchronous clocks, which can be tuned precisely within a wide frequency range, which makes them suitable for peripherals that require specific frequencies, such as timers and communication modules. the pm also contains advanced power-saving feat ures, allowing the user to optimize the power consumption for an application. the synchronous clocks are divided into three clock domains, one for the cpu and hsb, one for modules on the pba bus, and one for modules on the pbb bus.the three clocks can run at different speeds, so the user can save power by running periph- erals at a relatively low clock, while maintaining a high cpu performance. additionally, the clocks can be independently changed on-the-fly, without halting any peripherals. this enables the user to adjust the speed of the cpu and memo ries to the dynamic load of the application, without disturbing or re-configuring active peripherals. each module also has a separate clock, enabling t he user to switch off the clock for inactive modules, to save further pow er. additionally, clocks and os cillators can be automatically switched off during idle period s by using the sleep instruction on the cpu. the system will return to normal on occurrence of interrupts. the power manager also contains a reset contro ller, which collects all possible reset sources, generates hard and soft resets, and allows the reset source to be identified by software.
42 32072d?04/2011 at32uc3a3/a4 7.3 block diagram figure 7-1. power manager block diagram sleep controller oscillator and pll control pll0 pll1 synchronous clock generator generic clock generator reset controller oscillator 0 oscillator 1 rc oscillator startup counter slow clock sleep instruction power-on detector other reset sources resets generic clocks synchronous clocks cpu, hsb, pba, pbb osc/pll control signals rcsys 32 khz oscillator clk_32 interrupts external reset pad calibration registers brown-out detector voltage regulator fuses
43 32072d?04/2011 at32uc3a3/a4 7.4 product dependencies 7.4.1 i/o lines the pm provides a number of generic clock out puts, which can be connected to output pins, multiplexed with i/o lines. the user must first pr ogram the i/o controller to assign these pins to their peripheral function. if the i/o pins of the pm are not used by the ap plication, they can be used for other purposes by the i/o controller. 7.4.2 interrupt the pm interrupt line is connected to one of the internal sources of the interrupt controller. using the pm interrupt requires the interrupt controller to be programmed first. 7.5 functional description 7.5.1 slow clock the slow clock is generated from an internal rc oscillator which is always running, except in static mode. the slow clock can be used for th e main clock in the device, as described in sec- tion 7.5.5 . the slow clock is also used for the watchdog timer and measuring various delays in the power manager. the rc oscillator has a 3 cycles st artup time, and is always available when the cpu is running. the rc oscillator operates at approximately 115 khz. softw are can change rc oscillator cali- bration through the use of the rccr register. pleas e see the electrical characteristics section for details. rc oscillator can also be used as the rtc cl ock when crystal accura cy is not required. 7.5.2 oscillator 0 and 1 operation the two main oscillators are desi gned to be used with an external crystal and two biasing capac- itors, as shown in figure 7-2 on page 44 . oscillator 0 can be used for the main clock in the device, as described in section 7.5.5 . both oscillators can be used as source for the generic clocks, as described in section 7.5.8 . the oscillators are disabled by default after reset. wh en the oscillators ar e disabled, the xin and xout pins can be used as gener al purpose i/os. when the oscilla tors are configured to use an external clock, the clock must be applied to t he xin pin while the xout pin can be used as a general purpose i/o. the oscillators can be enabled by writing to the oscnen bits in mcctrl. operation mode (external clock or crysta l) is chosen by writing to the mode field in oscctrln. oscillators are automatically switched off in certain sleep modes to reduce power consumption, as described in section 7.5.7 . after a hard reset, or when wa king up from a sleep mode that di sabled the oscillators, the oscil- lators may need a certain amount of time to stabilize on the corr ect frequency. th is start-up time can be set in the oscctrln register. the pm masks the oscillator outputs during the start- up time, to ensure t hat no unstable clocks propagate to the digital logic. the oscnrdy bi ts in poscsr are automatically set and cleared according to the status of the oscillators. a zero to one transition on these bits can also be con- figured to generate an interrupt, as described in section 7.6.7 .
44 32072d?04/2011 at32uc3a3/a4 figure 7-2. oscillator connections 7.5.3 32 khz oscillator operation the 32 khz oscillator operates as described for oscillator 0 and 1 above. the 32 khz oscillator is used as source clock for the real-time counter. the oscillator is disabled by default, but can be enabled by writing osc32en in oscctrl32. the oscillator is an ultra-low po wer design and remains enabled in all sleep modes except static mode. while the 32 khz oscillator is disabled, the xin32 and xout32 pins are available as general purpose i/os. when the oscillator is configured to work with an external clock (mode field in oscctrl32 register), the external clock must be connected to xin32 while the xout32 pin can be used as a general purpose i/o. the startup time of the 32 khz oscillator can be set in the oscctrl32, after which osc32rdy in poscsr is set. an interrupt can be generated on a zero to one transition of osc32rdy. as a crystal oscillator usually requires a very long startup time (up to 1 second), the 32 khz oscillator will keep running across resets, except power-on-reset. 7.5.4 pll operation the device contains two plls, pll0 and pll1. these are disabled by default, but can be enabled to provide high frequency source clocks for synchronous or generic clocks. the plls can take either oscillator 0 or 1 as reference clock. t he pll output is divided by a multiplication factor, and the pll compares the resulting clock to the reference clock. the pll will adjust its output frequency until the two compared clocks are equal, thus locking the output frequency to a multiple of the reference clock frequency. when the pll is switched on, or when changing the clock source or multiplication factor for the pll, the pll is unlocked and the output frequency is undefined. the pll clock for the digital logic is automatically masked when the pll is unlocked, to prevent connected digital logic from receiving a too high frequency and thus become unstable. xin xout c 2 c 1
45 32072d?04/2011 at32uc3a3/a4 figure 7-3. pll with control logic and filters 7.5.4.1 enabling the pll plln is enabled by writing the pllen bit in th e plln register. pllosc selects oscillator 0 or 1 as clock source. the pllmul and plldiv bitfields must be written with the multiplication and division factors, respectively, creating the voltage controlled ocillator frequency f vco and the pll frequency f pll : if plldiv > 0 f in = f osc /2 ? plldiv f vco = (pllmul+1)/(plldiv) ? f osc if plldiv = 0 f in = f osc f vco = 2 ? (pllmul+1) ? f osc note: refer to electrical ch aracteristics section for f in and f vco frequency range. if pllopt[1] field is set to 0: f pll = f vco. if pllopt[1] field is set to 1: f pll = f vco / 2 . pll output divider 0 1 osc0 clock osc1 clock pllosc pllen pllopt pllmul lock mask pll clock input divider plldiv fin
46 32072d?04/2011 at32uc3a3/a4 the plln:pllopt field should be set to proper values according to the pll operating fre- quency. the pllopt field can also be set to divide the output frequency of the plls by 2. the lock signal for each pll is available as a lockn flag in poscsr. an interrupt can be gen- erated on a 0 to 1 transition of these bits. 7.5.5 synchronous clocks the slow clock (default), oscillato r 0, or pll0 provide the source for the main clock, which is the common root for the synchronous clocks for the cpu/hsb, pba, and pbb modules. the main clock is divided by an 8-bit prescaler, and ea ch of these four synchronous clocks can run from any tapping of this prescaler, or the undivided main clock, as long as f cpu f pba,b, . the synchro- nous clock source can be changed on-the fly, responding to varying load in the application. the clock domains can be shut down in sleep mode, as described in section 7.5.7 . additionally, the clocks for each module in the four domains can be individually masked, to avoid power con- sumption in inactive modules. figure 7-4. synchronous clock generation 7.5.5.1 selecting pll or oscillator for the main clock the common main clock can be connected to the slow clock, oscillator 0, or pll0. by default, the main clock will be connected to the slow clo ck. the user can connect the main clock to oscil- lator 0 or pll0 by writing the mcsel field in the main clock control register (mcctrl). this must only be done after that unit has been enabl ed, otherwise a deadlock will occur. care should also be taken that the new frequency of the synchronous clocks does not exceed the maximum frequency for each clock domain. mask prescaler osc0 clock pll0 clock mcsel 0 1 cpusel cpudiv main clock sleep controller cpumask cpu clocks hsb clocks pbaclocks pbb clocks sleep instruction slow clock
47 32072d?04/2011 at32uc3a3/a4 7.5.5.2 selecting synchronous clock division ratio the main clock feeds an 8-bit prescaler, which can be used to generate the synchronous clocks. by default, the synchronous clocks run on the undivided main clock. the user can select a pres- caler division for the cpu clock by writing c ksel.cpudiv to 1 and cpusel to the prescaling value, resulting in a cpu clock frequency: similarly, the clock for the pba, and pbb can be divided by writ ing their respective fields. to ensure correct operation, frequencies must be selected so that f cpu f pba,b . also, frequencies must never exceed the specified maxi mum frequency for each clock domain. cksel can be written without hal ting or disabling peripheral m odules. writing cksel allows a new clock setting to be written to all synchronous clocks at the sa me time. it is possible to keep one or more clocks unchanged by writing the same value a before to the xxxdiv and xxxsel fields. this way, it is possible to e.g. scale cpu and hsb speed according to the required perfor- mance, while keep ing the pba and pbb fr equency constant. for modules connected to the hsb bus, the pb clock frequency must be set to the same fre- quency than the cpu clock. 7.5.5.3 clock ready flag there is a slight delay from cksel is written and the new clock setting becomes effective. dur- ing this interval, the clock ready (c krdy) flag in isr will read as 0. if ier.ckrdy is written to one, the power manager interrupt can be triggered when the new clock setting is effective. cksel must not be re-written while ckrdy is zero, or the system may become unstable or hang. 7.5.6 peripheral clock masking by default, the clock for all modules are enabled, regardless of which modules are actually being used. it is possible to disable the clock for a module in the cpu, hsb, pba, or pbb clock domain by writing the corresponding bit in the clock mask register (cpu/hsb/pba/pbb) to 0. when a module is not clocked, it will cease operation, and its re gisters cannot be read or written. the module can be re-enabled later by writing the corresponding mask bit to 1. a module may be connected to several clock domains, in which case it will have several mask bits. table 7-7 on page 58 contains the list of implemented maskable clocks. 7.5.6.1 cautionary note the ocd clock must never be switched off if the user wishes to debug the device with a jtag debugger. note that clocks should only be switched off if it is certain that the module will not be used. switching off the clock for the internal ram will cause a pr oblem if the stack is mapped there. switching off the clock to the power manager (pm), which contains the mask registers, or the corresponding pbx bridge, will make it impossible to write the mask registers again. in this case, they can only be re-enabled by a system reset. f cpu f main 2 cpusel 1 + () ? =
48 32072d?04/2011 at32uc3a3/a4 7.5.6.2 mask ready flag due to synchronization in the clock generator, there is a slight delay from a mask register is writ- ten until the new mask setting goes into effect. when clearing mask bits, this delay can usually be ignored. however, when setting mask bits, the registers in the corresponding module must not be written until the clock has actually be re-enabled. the status flag mskrdy in isr pro- vides the required mask status information. when wr iting either mask register with any value, this bit is cleared. the bit is set when the clocks have been enabled and disabled according to the new mask setting. optionally, the power ma nager interrupt can be enabled by writing the mskrdy bit in ier. 7.5.7 sleep modes in normal operation, all clock domains are active, allowing software execution and peripheral operation. when the cpu is idle, it is possible to switch off the cpu clock and optionally other clock domains to save power. this is activate d by the sleep instruction, which takes the sleep mode index number as argument. 7.5.7.1 entering and exiting sleep modes the sleep instruction will halt the cpu and all modules belonging to t he stopped clock domains. the modules will be halted regardless of th e bit settings of the mask registers. oscillators and plls can also be switched off to save power. so me of these modules have a rel- atively long start-up time, and are only swit ched off when very low power consumption is required. the cpu and affected modules are restarted when the sleep mode is exited. this occurs when an interrupt triggers. note that even if an interrupt is enabled in sleep mode, it may not trigger if the source module is not clocked. 7.5.7.2 supported sleep modes the following sleep modes are supported. these are detailed in table 7-1 on page 49 . ? idle: the cpu is stopped, the rest of the chip is operating. wake-up sources are any interrupt. ? frozen: the cpu and hsb modules are stopped, peripherals are operating. wake-up sources are any interrupt from pb modules. ? standby: all synchronous clocks are stopped, but oscillators an d plls are running, allowing quick wake-up to normal mode. wake-up sources are rtc or external interrupt. ? stop: as standby, but oscillator 0 and 1, an d the plls are stopped. 32 khz (if enabled) and rc oscillators and rtc/wdt still operate. wake -up sources are rtc, external interrupt, or external reset pin. ? deepstop: all synchronous cloc ks, oscillator 0 and 1 and pll 0 and 1 are stopped. 32 khz oscillator can run if enabled. rc oscillator still operates. b andgap voltage reference, bod and bod33 are turned off. wake-up sources are rtc, external interrupt (eic) or external reset pin. ? static: all oscillators, including 32 khz and rc oscillator are stopp ed. bandgap voltage reference, bod and bod33 detectors are turned off. wake-up sources are external interrupt (eic) in asynchronous mode only or external reset pin.
49 32072d?04/2011 at32uc3a3/a4 the power level of the internal voltage regulator is also adjusted according to the sleep mode to reduce the internal regulator power consumption. 7.5.7.3 precautions when entering sleep mode modules communicating with external circuits should normally be disabled before entering a sleep mode that will stop the mo dule operation. this prevents erra tic behavior when entering or exiting sleep mode. please refer to the re levant module documentation for recommended actions. communication between the synchronous clock domains is disturbed when entering and exiting sleep modes. this means that bus transactions are not allowed between clock domains affected by the sleep mode. the system may hang if th e bus clocks are stopped in the middle of a bus transaction. the cpu is automatically stopped in a safe state to ensure that all cpu bus operations are com- plete when the sleep mode goes into effect. thus, when entering idle mode, no further action is necessary. when entering a sleep mode (except idle mode), all hsb masters must be stopped before entering the sleep mode. also, if there is a chance that any pb write operations are incomplete, the cpu should perform a read operation from any register on the pb bus before executing the sleep instruction. this will stall the cpu while waiting for any pend ing pb operations to complete. when entering a sleep mode deeper or equal to deepstop, the vbus asynchronous interrupt should be disabled (usbcon.vbuste = 0). 7.5.7.4 wake up the usb can be used to wake up the part from sleep modes through register awen of the power manager. 7.5.8 generic clocks timers, communication modules, and other modules connected to external circuitry may require specific clock frequencies to operate correctly . the power manager contains an implementation defined number of generic clocks that can prov ide a wide range of accurate clock frequencies. table 7-1. sleep modes index sleep mode cpu hsb pba,b gclk osc0,1 pll0,1, systimer osc32 rcsys bod & bod33 & bandgap voltage regulator 0 idle stop run run run run run on full power 1 frozen stop stop run run run run on full power 2 standby stop stop stop run run run on full power 3 stop stop stop stop stop run run on low power 4 deepstop stop stop stop stop run run off low power 5 static stop stop stop stop stop stop off low power
50 32072d?04/2011 at32uc3a3/a4 each generic clock module runs from either oscilla tor 0 or 1, or pll0 or 1. the selected source can optionally be divided by any even integer up to 512. each clock can be independently enabled and disabled, and is also automatically disabled along with peripheral clocks by the sleep controller. figure 7-5. generic clock generation 7.5.8.1 enabling a generic clock a generic clock is enabled by writi ng the cen bit in gcctrl to 1. each generic clock can use either oscillator 0 or 1 or pll0 or 1 as source, as select ed by the pllsel and oscsel bits. the source clock can optionally be divided by writing diven to 1 and the division factor to div, resulting in the output frequency: 7.5.8.2 disabling a generic clock the generic clock can be disabled by writing cen to zero or entering a sleep mode that disables the pb clocks. in either case, the generic clock will be switched off on the first falling edge after the disabling event, to ensu re that no glitches occur. if cen is written to 0, the bit will still read as 1 until the next falling edge occu rs, and the clock is actually sw itched off. when writing cen to 0, the other bits in gcctrl should not be changed until cen reads as 0, to avoid glitches on the generic clock. when the clock is disabled, both the prescaler and output are reset. 7.5.8.3 changing clock frequency when changing generic clock frequency by writing gcctrl, the clock should be switched off by the procedure above, before being re-enabled with the new clock source or division setting. this prevents glitches during the transition. divider 0 1 osc0 clock pll0 clock pllsel oscsel osc1 clock pll1 clock generic clock div 0 1 diven mask cen sleep controller f gclk f src 2 div 1 + () () ? =
51 32072d?04/2011 at32uc3a3/a4 7.5.8.4 generic clock implementation the generic clocks are allocated to different functions as shown in table 7-2 on page 51 . 7.5.9 divided pb clocks the clock generator in the power manager pr ovides divided pba and pbb clocks for use by peripherals that require a prescaled pbx clock. this is described in the documentation for the relevant modules. the divided clocks are not directly maskable, but are stopped in sleep modes where the pbx clocks are stopped. 7.5.10 debug operation the ocd clock must never be switched off if the user wishes to debug the device with a jtag debugger. during a debug session, the user may need to halt the system to inspect memory and cpu reg- isters. the clocks normally keep running during this debug opera tion, but some peripherals may require the clocks to be stopped, e.g. to prevent timer overflow, which would cause the program to fail. for this reason, peripherals on th e pba and pbb buses may use ?debug qualified? pbx clocks. this is described in the documentation for the relevant modules. the divided pbx clocks are always debug qualified clocks. debug qualified pbx clocks are stopped during debug operation. the debug system can option- ally keep these clocks running during the debug operation. this is described in the documentation for the on-chip debug system. 7.5.11 reset controller the reset controller collects the various reset sources in the system and generates hard and soft resets for the digital logic. the device contains a power-on detector, which keeps the system reset until power is stable. this eliminates the need for external reset circuitry to guarantee stable operation when powering up the device. it is also possible to reset the device by asserting the reset_n pin. this pin has an internal pul- lup, and does not need to be driven externally when negated. table 7-4 on page 53 lists these and other reset sources supported by the reset controller. table 7-2. generic clock allocation clock number function 0 gclk0 pin 1 gclk1 pin 2 gclk2 pin 3 gclk3 pin 4 gclk_usbb 5 gclk_abdac
52 32072d?04/2011 at32uc3a3/a4 figure 7-6. reset controller block diagram in addition to the listed reset types, the jtag can keep parts of the device statically reset through the jtag reset register. see jtag documentation for details. table 7-3. reset description when a reset occurs, some parts of the chip are not necessarily reset, depending on the reset source. only the power on reset (por ) will force a reset of the whole chip. reset source description power-on reset supply voltage below the power-on reset detector threshold voltage external reset reset_n pin asserted brownout reset supply voltage below the brownout reset detector threshold voltage cpu error caused by an illegal cpu access to external memory while in supervisor mode watchdog timer see watchdog timer documentation. ocd see on-chip debug documentation jtag reset controller reset_n power-o n detector ocd wdt rc_rcause cpu, hsb, pba, pbb ocd, rtc/wdt, clock generator brownout detector
53 32072d?04/2011 at32uc3a3/a4 table 7-4 on page 53 lists parts of the device that are reset, depending on the reset source. the cause of the last reset can be read from the rcause register. this register contains one bit for each reset source, and can be read during the boot sequence of an application to determine the proper action to be taken. 7.5.11.1 power-on detector the power-on detector monitors the vddcore supply pin and generates a reset when the device is powered on. the reset is active until the supply voltage from the linear regulator is above the power-on threshold leve l. the reset will be re -activated if the vo ltage drops below the power-on threshold level. see electrical characteristics for parametric details. 7.5.11.2 brown-out detector the brown-out detector (bod) monitors the vddcore supply pin and compares the supply voltage to the brown-out detection level, as set in bod.level. the bod is disabled by default, but can be enabled either by software or by flash fuses. the brown-out detector can either gen- erate an interrupt or a reset when the supply voltage is below the brown-out detection level. in any case, the bod output is available in bit poscsr.boddet bit. note that any change to the bo d.level field of the bod regist er should be done with the bod deactivated to avoid spurious reset or interrupt. see electrical characteristics chapter for parametric details. table 7-4. effect of the different reset events power-on reset external reset watchdog reset bod reset bod33 reset cpu error reset ocd reset cpu/hsb/pba/pbb (excluding power manager) yyy yyyy 32 khz oscillator y n n n n n n rtc control register y n n n n n n gplp registers y n n n n n n watchdog control register y y n y y y y voltage calibration register y n n n n n n rcsys calibration register y n n n n n n bod control register y y n n n n n bod33 control register y y n n n n n bandgap control register y y n n n n n clock control registers y y y y y y y osc0/osc1 and contro l registers y y y y y y y pll0/pll1 and control registers y y y y y y y ocd system and ocd registers y y n y y y n
54 32072d?04/2011 at32uc3a3/a4 7.5.11.3 brown-out detector 3v3 the brown-out detector 3v3 (bod33) monitors one vddio supply pin and compares the sup- ply voltage to the brown-out detection 3v3 level, which is typically calibrated at 2v7. the bod33 is enabled by default, but can be disabled by software. the brown-out detector 3v3 can either generate an interrupt or a reset when the supply voltage is below the brown-out detection3v3 level. in any case, the bod33 output is available in bit poscsr.bod33det bit. note that any change to the bo d33.level field of the bod33 regi ster should be done with the bod33 deactivated to avoid spurious reset or interrupt. the bod33.level default value is calibrated to 2v7 see electrical characteristics chapter for parametric details. table 7-5. vddio pin monitored by bod33 7.5.11.4 external reset the external reset detector monitors the state of the reset_n pin. by default, a low level on this pin will generate a reset. 7.5.12 calibration registers the power manager controls the calibration of the rc oscillator, voltage regulator, bandgap voltage reference through several calibrations registers. those calibration registers are loaded after a power on reset with default values stored in fac- tory-programmed flash fuses. although it is not reco mmended to override default factory settings, it is still possible to override these default values by writing to those register s. to prevent unexpected writes due to software bugs, write access to these registers is protected by a ?key?. first, a write to the register must be made with the field ?key? equal to 0x55 then a second write must be issued with the ?key? field equal to 0xaa. tfbga144 qfp144 vfbga100 h5 81 e5
55 32072d?04/2011 at32uc3a3/a4 7.6 user interface table 7-6. pm register memory map offset register register name access reset state 0x000 main clock control mcctrl read/write 0x00000000 0x0004 clock select cksel read/write 0x00000000 0x008 cpu mask cpumask read/write 0x00000003 0x00c hsb mask hsbmask read/write 0x00000fff 0x010 pba mask pbamask read/write 0x001fffff 0x014 pbb mask pbbmask read/write 0x000003ff 0x020 pll0 control pll0 read/write 0x00000000 0x024 pll1 control pll1 read/write 0x00000000 0x028 oscillator 0 control register oscctrl0 read/write 0x00000000 0x02c oscillator 1 control register oscctrl1 read/write 0x00000000 0x030 oscillator 32 control register oscctrl32 read/write 0x00000000 0x040 pm interrupt enable register ier write-only 0x00000000 0x044 pm interrupt disable register idr write-only 0x00000000 0x048 pm interrupt mask register imr read-only 0x00000000 0x04c pm interrupt status register isr read-only 0x00000000 00050 pm interrupt clear register icr write-only 0x00000000 0x054 power and oscillators status register poscsr read/write 0x00000000 0x060 generic clock control 0 gcctrl0 read/write 0x00000000 0x064 generic clock control 1 gcctrl1 read/write 0x00000000 0x068 generic clock control 2 gcctrl2 read/write 0x00000000 0x06c generic clock control 3 gcctrl3 read/write 0x00000000 0x070 generic clock control 4 gcctrl4 read/write 0x00000000 0x074 generic clock control 5 gcctrl5 read/write 0x00000000 0x0c0 rc oscillator cali bration register rccr read/write factory settings 0x0c4 bandgap calibration register bgcr read/write factory settings 0x0c8 linear regulator calibration regi ster vregcr read/write factory settings 0x0d0 bod level register bod read/write bod fuses in flash 0x0d4 bod33 level register bod33 read/write bod33 reset enable bod33 level=2v7 0x0140 reset cause register rcause read/write latest reset source 0x0144 asynchronous wake enable register awen read/write 0x00000000 0x200 general purpose low-power register gplp read/write 0x00000000
56 32072d?04/2011 at32uc3a3/a4 7.6.1 main clock control register name: mcctrl access type: read/write offset: 0x00 reset value: 0x00000000 ? osc1en: oscillator 1 enable 1: oscillator 1 is enabled 0: oscillator 1 is disabled ? osc0en: oscillator 0 enable 1: oscillator 0 is enabled 0: oscillator 0 is disabled ? mcsel: main clock select this field contains the clock selected as the main clock. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 ----osc1enosc0en mcsel mcsel selected clock 0b00 slow clock 0b01 oscillator 0 0b10 pll 0 0b11 reserved
57 32072d?04/2011 at32uc3a3/a4 7.6.2 clock select register name: cksel access type: read/write offset: 0x04 reset value: 0x00000000 ? pbbdiv: pbb division enable pbbdiv = 0: pbb clock equals main clock. pbbdiv = 1: pbb clock equals main clock divided by 2 (pbbsel+1) . ? pbadiv, pbasel: pba division and clock select pbadiv = 0: pba clock equals main clock. pbadiv = 1: pba clock equals main clock divided by 2 (pbasel+1) . ? cpudiv, cpusel: cpu/hsb division and clock select cpudiv = 0: cpu/hsb clock equals main clock. cpudiv = 1: cpu/hsb clock equals main clock divided by 2 (cpusel+1) . note that if xxxdiv is written to 0, xxxsel should also be written to 0 to ensure correct operation. also note that writing this register clears poscsr.ckrdy. the register mu st not be re-written until ckrdy goes high. 31 30 29 28 27 26 25 24 pbbdiv ---- pbbsel 23 22 21 20 19 18 17 16 pbadiv ---- pbasel 15 14 13 12 11 10 9 8 -------- 76543210 cpudiv---- cpusel
58 32072d?04/2011 at32uc3a3/a4 7.6.3 clock mask registers name: cpu/hsb/pba/pbbmask access type: read/write offset: 0x08-0x14 reset value: 0x00000003/0x00000fff/0x001fffff/0x000003ff ? mask: clock mask if bit n is written to zero, the clock for module n is stopped . if bit n is writen to one, the clock for module n is enabled ac cording to the current power mode. the number of impl emented bits in each mask register, as well as which module clock is controlled by each bit, is shown in table 7-7 on page 58 . 31 30 29 28 27 26 25 24 mask[31:24] 23 22 21 20 19 18 17 16 mask[23:16] 15 14 13 12 11 10 9 8 mask[15:8] 76543210 mask[7:0] table 7-7. maskable module clocks in at32uc3a3. bit cpumask hsbmask pbamask pbbmask 0 - flashc intc hmatrix 1ocd (1) pba bridge i/o usbb 2 - pbb bridge pdca flashc 3 - usbb pm/rtc/eic smc 4 - pdca adc sdramc 5 - ebi spi0 ecchrs 6 - pbc bridge spi1 mci 7- dmaca twim0 busmon 8 - busmon twim1 msi 9 - hramc0 twis0 aes 10 - hramc1 twis1 - 11 - (2) usart0 - 12 - - usart1 - 13 - - usart2 - 14 - - usart3 - 15 - - ssc -
59 32072d?04/2011 at32uc3a3/a4 note: 1. this bit must be set to one if the user wishes to debug the device with a jtag debugger. 2. this bits must be set to one 16 systimer (compare/count registers clk) -tc0- 17 - - tc1 - 18 - - abdac - 19 - - (2) - 20 - - (2) - 31:21 - - - - table 7-7. maskable module clocks in at32uc3a3. bit cpumask hsbmask pbamask pbbmask
60 32072d?04/2011 at32uc3a3/a4 7.6.4 pll control registers name: pll0,1 access type: read/write offset: 0x20-0x24 reset value: 0x00000000 ? plltest: pll test reserved for internal use. always write to 0. ? pllcount: pll count specifies the number of slow clock cycles before isr.lockn will be set after plln has been written, or after plln has been automatically re-enabled after exiting a sleep mode. ? pllmul: pll multiply factor ? plldiv: pll division factor these fields determine the ratio of the pll output frequency to the source oscillator frequency. formula is detallied in section 7.5.4.1 ? pllopt: pll option select the operating range for the pll. pllopt[0]: select the vco frequency range pllopt[1]: enable the extra output divider pllopt[2]: disable the wide-bandwidth mode (wide-bandwidth mode allows a faster startup time and out-of-lock time) ? pllosc: pll oscillator select 0: oscillator 0 is t he source for the pll. 1: oscillator 1 is t he source for the pll. 31 30 29 28 27 26 25 24 plltest - pllcount 23 22 21 20 19 18 17 16 ---- pllmul 15 14 13 12 11 10 9 8 ---- plldiv 76543210 - - - pllopt pllosc pllen description pllopt[0]: vco frequency 0 160mhz 61 32072d?04/2011 at32uc3a3/a4 ? pllen: pll enable 0: pll is disabled. 1: pll is enabled.
62 32072d?04/2011 at32uc3a3/a4 7.6.5 oscillator 0/1 control registers name : oscctrl0,1 access type: read/write offset: 0x28-0x2c reset value: 0x00000000 ? startup: oscillator startup time select startup time for the oscillator. ? mode: oscillator mode choose between crystal, or external clock 0: external clock connected on xin, xout can be used as an i/o (no crystal) 1 to 3: reserved 4: crystal is connected to xin/xout - o scillator is used with gain g0 ( xin from 0.4 mhz to 0.9 mhz ). 5: crystal is connected to xin/xout - o scillator is used with gain g1 ( xin from 0.9 mhz to 3.0 mhz ). 6: crystal is connected to xin/xout - o scillator is used with gain g2 ( xin from 3.0 mhz to 8.0 mhz ). 7: crystal is connected to xin/xout - o scillator is used with gain g3 ( xin from 8.0 mhz). 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 ----- startup 76543210 ----- mode startup number of rc oscillator clock cycle approximative equivalent time (rcsys = 115 khz) 00 0 1 64 560 us 2128 1.1ms 32048 18ms 44096 36ms 58192 71ms 6 16384 142 ms 7 reserved reserved
63 32072d?04/2011 at32uc3a3/a4 7.6.6 32 khz oscillator control register name: oscctrl32 access type: read/write offset: 0x30 reset value: 0x00000000 ? startup: oscillator startup time select startup time for 32 khz oscillator note: this register is only reset by power-on reset ? mode: oscillator mode choose between crystal, or external clock 0: external clock connected on xin32, xout32 can be used as a i/o (no crystal) 1: crystal is connected to xin32/xout32 - o scillator is used with automatic gain control 2 to 7: reserved ? osc32en: enable the 32 khz oscillator 0: 32 khz oscillator is disabled 1: 32 khz oscillator is enabled 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ----- startup 15 14 13 12 11 10 9 8 ----- mode 76543210 -------osc32en startup number of rc oscillator clock cycle approximative equivalent time (rcsys = 115 khz) 00 0 1128 1.1ms 2 8192 72.3 ms 3 16384 143 ms 4 65536 570 ms 5 131072 1.1 s 6 262144 2.3 s 7 524288 4.6 s
64 32072d?04/2011 at32uc3a3/a4 7.6.7 interrupt enable register name: ier access type: write-only offset: 0x40 reset value: 0x00000000 writing a one to a bit in this register will set the corresponding bit in imr. writing a zero to a bit in this register has no effect. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - - - bod33det boddet 15 14 13 12 11 10 9 8 - - - - - - osc32rdy osc1rdy 76543210 osc0rdy mskrdy ckrdy - - - lock1 lock0
65 32072d?04/2011 at32uc3a3/a4 7.6.8 interrupt disable register name: idr access type: write-only offset: 0x44 reset value: 0x00000000 writing a one to a bit in this register will clear the corresponding bit in imr. writing a zero to a bit in this register has no effect. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - - - bod33det boddet 15 14 13 12 11 10 9 8 - - - - - - osc32rdy osc1rdy 76543210 osc0rdy mskrdy ckrdy - - - lock1 lock0
66 32072d?04/2011 at32uc3a3/a4 7.6.9 interrupt mask register name: imr access type: read-only offset: 0x48 reset value: 0x00000000 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. a bit in this register is cleared when the corresponding bit in idr is written to one. a bit in this register is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - - - bod33det boddet 15 14 13 12 11 10 9 8 - - - - - - osc32rdy osc1rdy 76543210 osc0rdy mskrdy ckrdy - - - lock1 lock0
67 32072d?04/2011 at32uc3a3/a4 7.6.10 interrupt status register name: isr access type: read-only offset: 0x4c reset value: 0x00000000 ? bod33det: brown out detection this bit is set when a 0 to 1 transition on poscsr.bod33det bit is detected: bod33 has detected that power supply is going below bod33 reference value. this bit is cleared when the corresponding bit in icr is written to one. ? boddet: brown out detection this bit is set when a 0 to 1 transition on poscsr.boddet bit is detected: bod has detected that power supply is going below bod reference value. this bit is cleared when the corresponding bit in icr is written to one. ? osc32rdy: 32 khz oscillator ready this bit is set when a 0 to 1 transition on the poscsr.osc32rdy bit is detected: the 32 khz oscillator is stable and ready to be used as clock source. this bit is cleared when the corresponding bit in icr is written to one. ? osc1rdy: oscillator 1 ready this bit is set when a 0 to 1 transition on the poscsr.osc1rdy bit is detected: oscillator 1 is stable and ready to be used as clock source. this bit is cleared when the corresponding bit in icr is written to one. ? osc0rdy: oscillator 0 ready this bit is set when a 0 to 1 transition on the poscsr.osc1rdy bit is detected: oscillator 1 is stable and ready to be used as clock source. this bit is cleared when the corresponding bit in icr is written to one. ? mskrdy: mask ready this bit is set when a 0 to 1 transition on the poscsr.mskrdy bit is detected: clocks are now masked according to the (cpu/hsb/pba/pbb)_mask registers. this bit is cleared when the corresponding bit in icr is written to one. ? ckrdy: clock ready 0: the cksel register has been written, and the new clock setting is not yet effective. 1: the synchronous clocks have frequencies as indicated in the cksel register. note: writing a one to icr.ckrdy has no effect. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - - - bod33det boddet 15 14 13 12 11 10 9 8 - - - - - - osc32rdy osc1rdy 76543210 osc0rdy mskrdy ckrdy - - - lock1 lock0
68 32072d?04/2011 at32uc3a3/a4 ? lock1: pll1 locked this bit is set when a 0 to 1 transitio n on the poscsr.lock1 bit is detected: pll 1 is locked and ready to be selected as clock source. this bit is cleared when the corresponding bit in icr is written to one. ? lock0: pll0 locked this bit is set when a 0 to 1 transitio n on the poscsr.lock0 bit is detected: pll 0 is locked and ready to be selected as clock source. this bit is cleared when the corresponding bit in icr is written to one.
69 32072d?04/2011 at32uc3a3/a4 7.6.11 interrupt clear register name: icr access type: write-only offset: 0x50 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in isr and the corresponding interrupt request. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - - - bod33det boddet 15 14 13 12 11 10 9 8 - - - - - - osc32rdy osc1rdy 76543210 osc0rdy mskrdy ckrdy - - - lock1 lock0
70 32072d?04/2011 at32uc3a3/a4 7.6.12 power and oscillators status register name: poscsr access type: read-only offset: 0x54 reset value: 0x00000000 ? bod33det: brown out 3v3 detection 0: no bod33 event 1: bod33 has detected that power supply is going below bod33 reference value. ? boddet: brown out detection 0: no bod event 1: bod has detected that power suppl y is going below bod reference value. ? osc32rdy: 32 khz oscillator ready 0: the 32 khz oscillator is not enabled or not ready. 1: the 32 khz oscillator is stable and ready to be used as clock source. ? osc1rdy: osc1 ready 0: oscillator 1 not enabled or not ready. 1: oscillator 1 is stable and ready to be used as clock source. ? osc0rdy: osc0 ready 0: oscillator 0 not enabled or not ready. 1: oscillator 0 is stable and ready to be used as clock source. ? mskrdy: mask ready 0: mask register has been changed, masking in progress. 1: clock are masked according to xxx_mask ? ckrdy: 0: the cksel register has been written, and the new clock setting is not yet effective. 1: the synchronous clocks have frequencies as indicated in the cksel register. ? lock1: pll 1 locked 0:pll 1 is unlocked 1:pll 1 is locked, and ready to be selected as clock source. ? lock0: pll 0 locked 0: pll 0 is unlocked 1: pll 0 is locked, and ready to be selected as clock source. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ------bod33detboddet 15 14 13 12 11 10 9 8 ------osc32rdyosc1rdy 76543210 osc0rdy mskrdy ckrdy - - - lock1 lock0
71 32072d?04/2011 at32uc3a3/a4 7.6.13 generic clock control register name: gcctrlx access type: read/write offset: 0x60 - 0x74 reset value: 0x00000000 there is one gcctrl register per generic clock in the design. ? div: division factor ? diven: divide enable 0: the generic clock equals the undivided source clock. 1: the generic clock equals the source clock divided by 2*(div+1). ? cen: clock enable 0: clock is stopped. 1: clock is running. ? pllsel: pll select 0: oscillator is source for the generic clock. 1: pll is source for the generic clock. ? oscsel: oscillator select 0: oscillator (or pll) 0 is source for the generic clock. 1: oscillator (or pll) 1 is source for the generic clock. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 div[7:0] 76543210 - - - diven - cen pllsel oscsel
72 32072d?04/2011 at32uc3a3/a4 7.6.14 rc oscillator calibration register name: rccr access type: read/write offset: 0xc0 reset value: 0x00000000 ? key: register write protection this field must be written twice, first with key value 0x 55, then 0xaa, for a write operation to have an effect. ? fcd: flash calibration done set to 1 when ctrl, hyst, and level fiel ds have been updated by the flash fuses af ter power-on reset, or after flash fuses are reprogrammed. the ctrl, hyst and level values will not be updated again by the flash fuses until a new power-on reset or the fcd field is written to zero. ? calib: calibration value calibration value for the rc oscillator. 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 -------fcd 15 14 13 12 11 10 9 8 ------ calib 76543210 calib
73 32072d?04/2011 at32uc3a3/a4 7.6.15 bandgap calibration register name: bgcr access type: read/write offset: 0xc4 reset value: 0x00000000 ? key: register write protection this field must be written twice, first with key value 0x 55, then 0xaa, for a write operation to have an effect. ? fcd: flash calibration done set to 1 when the calib field has been updated by the fl ash fuses after power-on reset or when the flash fuses are reprogrammed. the calib field will not be updated again by the flash fuses until a new power-on reset or the fcd field is written to zero. ? calib: calibration value calibration value for bandgap. see electrical characteristics for voltage values. 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 -------fcd 15 14 13 12 11 10 9 8 -------- 76543210 ----- calib
74 32072d?04/2011 at32uc3a3/a4 7.6.16 pm voltage regulator calibration register name: vregcr access type: read/write offset: 0xc8 reset value: 0x00000000 ? key: register write protection this field must be written twice, first with key value 0x 55, then 0xaa, for a write operation to have an effect. calibration value for voltage regulator. see electrical characteristics for voltage values. ? fcd: flash calibration done set to 1 when the calib field has been updated by the fl ash fuses after power-on reset or when the flash fuses are reprogrammed. the calib field will not be updated again by the flash fuses until a new power-on reset or the fcd field is written to zero. ? calib: calibration value 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 -------fcd 15 14 13 12 11 10 9 8 -------- 76543210 ----- calib
75 32072d?04/2011 at32uc3a3/a4 7.6.17 bod control register name: bod access type: read/write offset: 0xd0 reset value: 0x00000000 ? key: register write protection this field must be written twice, first with key value 0x 55, then 0xaa, for a write operation to have an effect. ? fcd: bod fuse calibration done set to 1 when ctrl, hyst and level fields has been updated by the flash fuse s after power-on reset or flash fuses update if one, the ctrl, hyst and level values will not be updated again by flash fuses can be cleared to allow subsequent over writing of the value by flash fuses ? ctrl: bod control 0: bod is off 1: bod is enabled and can reset the chip 2: bod is enabled and but cannot reset the chip. only interrupt wi ll be sent to interrupt controller, if enabled in the imr reg ister. 3: bod is off ? hyst: bod hysteresis 0: no hysteresis 1: hysteresis on ? level: bod level this field sets the triggering threshold of the bod. se e electrical characteristics for actual voltage levels. note that any change to the level field of the bod register should be done with the bod deactivated to avoid spurious reset or interrupt. 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 -------fcd 15 14 13 12 11 10 9 8 ------ ctrl 76543210 - hyst level
76 32072d?04/2011 at32uc3a3/a4 7.6.18 bod33 co ntrol register name: bod33 access type: read/write offset: 0xd4 reset value: 0x0000010x ? key: register write protection this field must be written twice, first with key value 0x 55, then 0xaa, for a write operation to have an effect. ? fcd: bod33 fuse calibration done set to 1 when level field has been updated by the flas h fuses after power-on re set or flash fuses update if one, the level value will not be updated again by flash fuses can be cleared to allow subsequent over writing of the value by flash fuses ? ctrl: bod33 control 0: bod33 is off 1: bod33 is enabled and can reset the chip 2: bod33 is enabled and but cannot reset the chip. only interrupt will be sent to interrupt controller, if enabled in the imr register. 3: bod33 is off ? level: bod33 level this field sets the triggering threshold of the bod33. see electrical characteristics for actual voltage levels. note that any change to the level field of the bod33 register should be done with the bod33 deactivated to avoid spurious reset or interrupt. 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 -------fcd 15 14 13 12 11 10 9 8 ------ ctrl 76543210 -- level
77 32072d?04/2011 at32uc3a3/a4 7.6.19 reset cause register name: rcause access type: read-only offset: 0x140 reset value: 0x00000000 ? bod33: brown-out 3v3 reset the cpu was reset due to the supply voltage 3v3 being lower than the brown-out threshold level. ? ocdrst: ocd reset the cpu was reset because the res strobe in the ocd development control register has been written to one. ? cpuerr: cpu error the cpu was reset because it had detected an illegal access. ? jtag: jtag reset the cpu was reset by setting the bit rc_cpu in the jtag reset register. ? wdt: watchdog reset the cpu was reset because of a watchdog timeout. ? ext: external reset pin the cpu was reset due to t he reset pin being asserted. ? bod: brown-out reset the cpu was reset due to the supply voltage 1v8 being lower than the brown-out threshold level. ? por power-on reset the cpu was reset due to the supply voltage being lower than the power-on threshold level. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -----bod33-ocdrst 76543210 cpuerr - - jtag wdt ext bod por
78 32072d?04/2011 at32uc3a3/a4 7.6.20 asynchronous wake up enable name: awen access type: read/write offset: 0x144 reset value: - ? usb_waken : wake up enable register writing a zero to this bit will disable the usb wake up. writing a one to this bit will enable the usb wake up. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------usb_w aken
79 32072d?04/2011 at32uc3a3/a4 7.6.21 general purpose low-power register name: gplp access type: read/write offset: 0x200 reset value: 0x00000000 these registers are general purpose 32-bit registers that are reset only by power-on- reset. any other reset will keep the conte nt of these registers untouched. user softwar e can use these register to save context variables in a very low power mode. two gplp register are implemented in at32uc3a3. 31 30 29 28 27 26 25 24 gplp 23 22 21 20 19 18 17 16 gplp 15 14 13 12 11 10 9 8 gplp 76543210 gplp
80 32072d?04/2011 at32uc3a3/a4 8. real time counter (rtc) rev: 2.4.0.1 8.1 features ? 32-bit real-time counte r with 16-bit prescaler ? clocked from rc oscillator or 32khz oscillator ? long delays ? max timeout 272years ? high resoluti on: max count frequency 16khz ? extremely low power consumption ? available in all sleep modes except static ? interrupt on wrap 8.2 overview the real time counter (rtc) enables periodic in terrupts at long intervals, or accurate mea- surement of real-time sequences. the rtc is fed from a 16-bit prescaler, which is clocked from the system rc oscillator or the 32khz crysta l oscillator. any tapping of the prescaler can be selected as clock source for the rtc, enabling both high resolution and long timeouts. the pres- caler cannot be written directly, but can be cleared by the user. the rtc can generate an interrupt when the counter wraps around the value stored in the top register (top), producing accurate periodic interrupts. 8.3 block diagram figure 8-1. real time counter block diagram 8.4 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 16-bit prescaler rcsys 32-bit counter val top topi irq clk_32 ctrl en clk32 psel 1 0
81 32072d?04/2011 at32uc3a3/a4 8.4.1 power management the rtc remains operating in all sleep modes except static mode. interrupts are not available in deepstop mode. 8.4.2 clocks the rtc can use the system rc oscillator as cloc k source. this oscillator is always enabled whenever this module is active. please refer to the electrical characteristics chapter for the characteristic frequency of this oscillator (f rc ). the rtc can also use the 32 khz crystal oscilla tor as clock source. this oscillator must be enabled before use. please refer to the power manager chapter for details. the clock for the rtc bus interface (clk_rtc) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to disable the rtc before disabling the clock, to avoid freezing the rtc in an undefined state. 8.4.3 interrupts the rtc interrupt request line is connected to the interrupt controller. using the rtc interrupt requires the interrupt controller to be programmed first. 8.4.4 debug operation the rtc prescaler is frozen during debug operation, unless the ocd system keeps peripherals running in debug operation. 8.5 functional description 8.5.1 rtc operation 8.5.1.1 source clock the rtc is enabled by writing a one to the enab le bit in the control register (ctrl.en). the 16-bit prescaler will then increment on the selected clock. the pres caler cannot be read or writ- ten, but it can be reset by writing a one to the prescaler clear bit in ctrl register (ctrl.pclr). the 32khz oscillator select bit in ctrl register (ctrl.clk32) selects ei ther the rc oscillator or the 32khz oscillator as clock source (defined as input in the formula below) for the prescaler. the prescale select field in ctrl register (c trl.psel) selects the presca ler tapping, selecting the source clock for the rtc: 8.5.1.2 counter operation when enabled, the rtc will increment until it reaches top, and then wraps to 0x0. the status bit topi in interrupt status register (isr) is set to one when this occurs. from 0x0 the counter will count top+1 cycles of the source clock before it wraps back to 0x0. f rtc f input 2 ? psel 1 + () =
82 32072d?04/2011 at32uc3a3/a4 the rtc count value can be read from or written to the value register (val). due to synchroni- zation, continuous reading of the val register with the lowest prescaler setting will skip every other value. 8.5.1.3 rtc interrupt the rtc interrupt is enabled by writing a one to the top interrupt bit in the interrupt enable reg- ister (ier.topi), and is disabled by writing a on e to the top interrupt bit in the interrupt disable register (idr.topi). the interrupt mask register (imr) can be read to see whether or not the interrupt is enabled. if enabled, an interrupt will be generated if t he topi bit in th e interrupt sta- tus register (isr) is set. the topi bit in isr can be cleared by writing a one to the topi bit in the interrupt clear register (icr.topi). the rtc interrupt can wake the cpu from all sleep modes except deepstop and static modes. 8.5.1.4 rtc wakeup the rtc can also wake up the cpu directly wi thout triggering an interrupt when the isr.topi bit is set. in this case, the cpu will continue executing from the instruction following the sleep instruction. this direct rtc wake-up is enabled by writing a one to the wake enable bit in the ctrl register (ctrl.waken). when the cpu wakes from sleep, the ctrl.waken bit must be written to zero to clear the internal wake signal to the sleep controller, otherwise a new sleep instruction will have no effect. the rtc wakeup is available in all sleep modes except static mode. the rtc wakeup can be configured independently of the rtc interrupt. 8.5.1.5 busy bit due to the crossing of clock domains, the rtc uses a few clock cycles to propagate the values stored in ctrl, top, and val to the rtc. the rtc busy bit in ctrl (ctrl.busy) indicates that a register write is still go ing on and all writes to top, ctrl, and val will be discarded until the ctrl.busy bit goes low again.
83 32072d?04/2011 at32uc3a3/a4 8.6 user interface table 8-1. rtc register memory map offset register register name access reset 0x00 control register ctrl read/write 0x00010000 0x04 value register val read/write 0x00000000 0x08 top register top read/write 0xffffffff 0x10 interrupt enable register ier write-only 0x00000000 0x14 interrupt disable register idr write-only 0x00000000 0x18 interrupt mask register imr read-only 0x00000000 0x1c interrupt status register isr read-only 0x00000000 0x20 interrupt clear register icr write-only 0x00000000
84 32072d?04/2011 at32uc3a3/a4 8.6.1 control register name: ctrl access type: read/write offset: 0x00 reset value: 0x00010000 ? clken: clock enable 1: the clock is enabled. 0: the clock is disabled. ? psel: prescale select selects prescaler bit psel as source clock for the rtc. ? busy: rtc busy this bit is set when the rtc is busy and will discard writes to top, val, and ctrl. this bit is cleared when the rtc acc epts writes to top, val, and ctrl. ? clk32: 32 khz oscillator select 1: the rtc uses the 32 khz oscillator as clock source. 0: the rtc uses the rc oscillator as clock source. ? waken: wakeup enable 1: the rtc wakes up the cpu from sleep modes. 0: the rtc does not wake up the cpu from sleep modes. ? pclr: prescaler clear writing a one to this bit clears the prescaler. writing a zero to this bit has no effect. this bit always reads as zero. ? en: enable 1: the rtc is enabled. 0: the rtc is disabled. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------clken 15 14 13 12 11 10 9 8 - - - - psel 76543210 - - - busy clk32 waken pclr en
85 32072d?04/2011 at32uc3a3/a4 8.6.2 value register name: val access type: read/write offset: 0x04 reset value: 0x00000000 ? val[31:0]: rtc value this value is incremented on every rising edge of the source clock. 31 30 29 28 27 26 25 24 val[31:24] 23 22 21 20 19 18 17 16 val[23:16] 15 14 13 12 11 10 9 8 val[15:8] 76543210 val[7:0]
86 32072d?04/2011 at32uc3a3/a4 8.6.3 top register name: top access type: read/write offset: 0x08 reset value: 0xffffffff ? val[31:0]: rtc top value val wraps at this value. 31 30 29 28 27 26 25 24 val[31:24] 23 22 21 20 19 18 17 16 val[23:16] 15 14 13 12 11 10 9 8 val[15:8] 76543210 val[7:0]
87 32072d?04/2011 at32uc3a3/a4 8.6.4 interrupt enable register name: ier access type: write-only offset: 0x10 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will set the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------topi
88 32072d?04/2011 at32uc3a3/a4 8.6.5 interrupt disable register name: idr access type: write-only offset: 0x14 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------topi
89 32072d?04/2011 at32uc3a3/a4 8.6.6 interrupt mask register name: imr access type: read-only offset: 0x18 reset value: 0x00000000 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. a bit in this register is cleared when the corresponding bit in idr is written to one. a bit in this register is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------topi
90 32072d?04/2011 at32uc3a3/a4 8.6.7 interrupt status register name: isr access type: read-only offset: 0x1c reset value: 0x00000000 ? topi: top interrupt this bit is set when val has wrapped at its top value. this bit is cleared when the corresponding bit in icr is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------topi
91 32072d?04/2011 at32uc3a3/a4 8.6.8 interrupt clear register name: icr access type: write-only offset: 0x20 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in sr and the corresponding interrupt request. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------topi
92 32072d?04/2011 at32uc3a3/a4 9. watchdog timer (wdt) rev: 2.4.0.1 9.1 features ? watchdog timer counter with 32-bit prescaler ? clocked from the system rc oscillator (rcsys) 9.2 overview the watchdog timer (wdt) has a prescaler generating a time-out period. this prescaler is clocked from the rc oscillator. th e watchdog timer must be periodic ally reset by software within the time-out period, otherwise, the device is rese t and starts executing from the boot vector. this allows the device to recover from a condition that has caused the system to be unstable. 9.3 block diagram figure 9-1. wdt block diagram 9.4 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 9.4.1 power management when the wdt is enabled, the wdt remains clocked in all sleep modes, and it is not possible to enter static mode. 9.4.2 clocks the wdt can use the system rc o scillator (rcsys) as clock sour ce. this oscillator is always enabled whenever these modules are active. please refer to the electrical characteristics chap- ter for the characteristic fr equency of this oscillator (f rc ). 9.4.3 debug operation the wdt prescaler is frozen during debug opera tion, unless the on-chip debug (ocd) system keeps peripherals running in debug operation. rcsys clr watchdog detector ctrl 32-bit prescaler watchdog reset en
93 32072d?04/2011 at32uc3a3/a4 9.5 functional description the wdt is enabled by writing a one to the enable bit in the control register (ctrl.en). this also enables the system rc clock (clk_rcsys) fo r the prescaler. the pr escale select field (psel) in the ctrl register selects the watchdog time-out period: t wdt = 2 (psel+1) / f rc the next time-out period will b egin as soon as the watchdog re set has occurred and count down during the reset sequence. care must be taken when selecting the psel field value so that the time-out period is greater than the startup time of the chip, otherwise a watchdog reset can reset the chip before any code has been run. to avoid accidental disabling of the watchdog, the ctrl register must be written twice, first with the key field set to 0x55, then 0x aa without changing the other bi ts. failure to do so will cause the write operation to be ignored, an d the ctrl register value will not change. the clear register (clr) must be written with any value with regular intervals shorter than the watchdog time-out period. otherwise, the device will receive a soft reset, and the code will start executing from the boot vector. when the wdt is enabled, it is not possible to enter static mo de. attempting to do so will result in entering shutdown mode, leaving the wdt operational. 9.6 user interface table 9-1. wdt register memory map offset register register name access reset 0x00 control register ctrl read/write 0x00000000 0x04 clear register clr write-only 0x00000000
94 32072d?04/2011 at32uc3a3/a4 9.6.1 control register name: ctrl access type: read/write offset: 0x00 reset value: 0x00000000 ? key: write protection key this field must be written twice, first with key val ue 0x55, then 0xaa, for a write operation to be effective. this field always reads as zero. ? psel: prescale select psel is used as watch dog timeou t period. ? en: wdt enable 1: wdt is enabled. 0: wdt is disabled. 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - psel 76543210 -------en
95 32072d?04/2011 at32uc3a3/a4 9.6.2 clear register name: clr access type: write-only offset: 0x04 reset value: 0x00000000 ?clr: writing periodically any value to this field when the wdt is enabled, within the watchdog ti me-out period, will prevent a watchdog reset. this field always reads as zero. 31 30 29 28 27 26 25 24 clr[31:24] 23 22 21 20 19 18 17 16 clr[23:16] 15 14 13 12 11 10 9 8 clr[15:8] 76543210 clr[7:0]
96 32072d?04/2011 at32uc3a3/a4 10. interrupt controller (intc) rev: 1.0.1.5 10.1 features ? autovectored low latency interrupt service with programmable priority ? 4 priority levels for regular, maskable interrupts ? one non-maskable interrupt ? up to 64 groups of interrupts with up to 32 interrupt requests in each group 10.2 overview the intc collects interrupt requests from the peripherals, prioritizes them, and delivers an inter- rupt request and an autovector to the cpu. the avr32 architecture supports 4 priority levels for regular, maskable interrupts, and a non-maskable interrupt (nmi). the intc supports up to 64 groups of interrupts. each group can have up to 32 interrupt request lines, these lines are connected to the peripherals. each group has an interrupt priority register (ipr) and an interrupt request register (irr). the iprs are used to assign a priority level and an autovector to each group, and the irrs are used to identify the active interrupt request within each group. if a group has only one interrupt request line, an active interrupt group uniquely identifies the active interrupt request line, and the corresponding irr is not needed. the intc also provides one interrupt cause register (icr) per priority level. these registers identify the group that has a pending interrupt of the corresponding priority level. if several groups have a pending interrupt of the same level, the group with the lowest number takes priority. 10.3 block diagram figure 10-1 gives an overview of the intc. the grey boxes represent registers that can be accessed via the user interface. the interrupt requests from the peripherals (ireqn) and the nmi are input on the left side of the figure. signals to and from the cpu are on the right side of the figure.
97 32072d?04/2011 at32uc3a3/a4 figure 10-1. intc block diagram 10.4 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 10.4.1 power management if the cpu enters a sleep mode that disables clk_sync, the intc will stop functioning and resume operation after the system wakes up from sleep mode. 10.4.2 clocks the clock for the intc bus interface (clk_intc) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. the intc sampling logic runs on a clock which is stopped in any of the sleep modes where the system rc oscillator is not running. this cl ock is referred to as clk_sync. this clock is enabled at reset, and only turned off in sleep modes wher e the system rc oscillator is stopped. 10.4.3 debug operation when an external debugger forces the cpu into debug mode, the intc continues normal operation. 10.5 functional description all of the incoming interrupt requests (ireqs) are sampled into the corresponding interrupt request register (irr). the irrs must be accessed to identify which ireq within a group that is active. if several ireqs within the same group are active, the interrupt service routine must prioritize between them. all of the input lines in each group are logically ored together to form the grpreqn lines, indicating if there is a pending interrupt in the corresponding group. the request masking hardware maps each of the grpreq lines to a priority level from int0 to int3 by associating each grou p with the interrupt level (int level) field in the corresponding request masking or ireq0 ireq1 ireq2 ireq31 grpreq0 masks sreg masks i[3-0]m gm intlevel autovector prioritizer cpu interrupt controller or grpreqn nmireq or ireq32 ireq33 ireq34 ireq63 grpreq1 irr registers ipr registers icr registers int_level, offset int_level, offset int_level, offset ipr0 ipr1 iprn irr0 irr1 irrn valreq0 valreq1 valreqn . . . . . . . . .
98 32072d?04/2011 at32uc3a3/a4 interrupt priority register (ipr). the grpreq inputs are then masked by the mask bits from the cpu status register. any interrupt group that has a pending interrupt of a priority level that is not masked by the cpu status register, gets its corresponding valreq line asserted. masking of the interrupt requests is done based on five interrupt mask bits of the cpu status register, namely interrupt level 3 mask (i3m) to interrupt level 0 mask (i0m), and global inter- rupt mask (gm). an interrupt request is masked if either the gm or the corresponding interrupt level mask bit is set. the prioritizer hardware uses th e valreq lines and the intlevel fi eld in the iprs to select the pending interrupt of the highest priority. if an nm i interrupt request is pending, it automatically gets the highest priority of any pending interrupt. if several interrupt groups of the highest pend- ing interrupt level have pending interrupts, the interrupt group with the lowest number is selected. the intlevel and handler autovector offset (autovector) of the selected interrupt are transmitted to the cpu for interrupt handling an d context switching. the cpu does not need to know which interrupt is requesting handling, but only the level and the offset of the handler address. the irr registers contain the interrupt request lines of the groups and can be read via user interface registers for checking which interrupts of the group are actually active. the delay through the intc from the peripheral interrupt request is set until the interrupt request to the cpu is set is three cycles of clk_sync. 10.5.1 non-maskable interrupts a nmi request has priority over all other interrupt requests. nmi has a dedicated exception vec- tor address defined by the avr32 architec ture, so autovector is undefined when intlevel indicates that an nmi is pending. 10.5.2 cpu response when the cpu receives an interr upt request it checks if any othe r exceptions are pending. if no exceptions of higher priority are pending, interr upt handling is initiated. when initiating interrupt handling, the corresponding interrupt mask bit is se t automatically for this and lower levels in sta- tus register. e.g, if an interrupt of level 3 is approved for handling, the interrupt mask bits i3m, i2m, i1m, and i0m are set in status register. if an interrupt of level 1 is approved, the masking bits i1m and i0m are set in status register. th e handler address is calculated by logical or of the autovector to the cpu system register exception vector base address (evba). the cpu will then jump to the calculated address and start executing th e interrupt handler. setting the interrupt mask bits prevents the interrupts from the same and lower levels to be passed through the interrupt controller. setting of the same level mask bit prevents also multiple requests of the same interrupt to happen. it is the responsibility of the ha ndler software to clear the interrupt request that caused the inter- rupt before returning from the interrupt handler. if the conditions that caused the interrupt are not cleared, the interrupt request remains active. 10.5.3 clearing an interrupt request clearing of the interrupt request is done by writing to registers in the corresponding peripheral module, which then clears the corresponding nmireq/ireq signal. the recommended way of clearing an interrupt request is a store operation to the controlling peripheral register, followed by a dummy load operat ion from the same register. this causes a
99 32072d?04/2011 at32uc3a3/a4 pipeline stall, which prevents the interrupt from accidentally re-triggering in case the handler is exited and the interrupt mask is cleared before the interrupt request is cleared.
100 32072d?04/2011 at32uc3a3/a4 10.6 user interface table 10-1. intc register memory map offset register register name access reset 0x000 interrupt priority register 0 ipr0 read/write 0x00000000 0x004 interrupt priority register 1 ipr1 read/write 0x00000000 ... ... ... ... ... 0x0fc interrupt priority register 63 ipr63 read/write 0x00000000 0x100 interrupt request register 0 irr0 read-only n/a 0x104 interrupt request register 1 irr1 read-only n/a ... ... ... ... ... 0x1fc interrupt request regi ster 63 irr63 read-only n/a 0x200 interrupt cause register 3 icr3 read-only n/a 0x204 interrupt cause register 2 icr2 read-only n/a 0x208 interrupt cause register 1 icr1 read-only n/a 0x20c interrupt cause register 0 icr0 read-only n/a
101 32072d?04/2011 at32uc3a3/a4 10.6.1 interrupt priority registers name : ipr0...ipr63 access type: read/write offset: 0x000 - 0x0fc reset value: 0x00000000 ? intlevel: interrupt level indicates the evba-relative offs et of the interrup t handler of the co rresponding group: 00: int0: lowest priority 01: int1 10: int2 11: int3: highest priority ? autovector: autovector address handler offset is used to give the address of the interrupt handle r. the least significant bit should be written to zero to giv e halfword alignment. 31 30 29 28 27 26 25 24 intlevel[1:0] ------ 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - autovector[13:8] 76543210 autovector[7:0]
102 32072d?04/2011 at32uc3a3/a4 10.6.2 interrupt request registers name : irr0...irr63 access type: read-only offset: 0x0ff - 0x1fc reset value: n/a ? irr: interrupt request line this bit is cleared when no interrupt request is pending on this input request line. this bit is set when an interrupt request is pending on this input request line. the are 64 irrs, one for each group. each irr has 32 bits, one for each possible interrupt request, for a total of 2048 possibl e input lines. the irrs are read by the software interrupt handler in order to determine which interrupt request is pending. the irrs are sampled continuously, and are read-only. 31 30 29 28 27 26 25 24 irr[32*x+31] irr[32*x+30] irr[32*x+ 29] irr[32*x+28] irr[32* x+27] irr[32*x+26] irr[32*x+25] irr[32*x+24] 23 22 21 20 19 18 17 16 irr[32*x+23] irr[32*x+22] irr[32*x+ 21] irr[32*x+20] irr[32* x+19] irr[32*x+18] irr[32*x+17] irr[32*x+16] 15 14 13 12 11 10 9 8 irr[32*x+15] irr[32*x+14] irr[32*x+ 13] irr[32*x+12] irr[32*x+ 11] irr[32*x+10] irr[32*x+9] irr[32*x+8] 76543210 irr[32*x+7] irr[32*x+6] irr[32*x+5] irr[32*x+4] irr[32*x+3] irr[32*x+2] irr[32*x+1] irr[32*x+0]
103 32072d?04/2011 at32uc3a3/a4 10.6.3 interrupt cause registers name : icr0...icr3 access type: read-only offset: 0x200 - 0x20c reset value: n/a ? cause: interrupt group causing interrupt of priority n icrn identifies the group with the highest pr iority that has a pending interrupt of le vel n. this value is only defined when at least one interrupt of level n is pending. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -- cause
104 32072d?04/2011 at32uc3a3/a4 10.7 interrupt r equest signal map the various modules may output interrupt request signals. these signals are routed to the inter- rupt controller (intc), described in a later c hapter. the interrupt controller supports up to 64 groups of interrupt requests. each group can have up to 32 interrupt request signals. all interrupt signals in the same group share the same autov ector address and priority level. refer to the documentation for the individual submodules for a description of the semantics of the different interrupt requests. the interrupt request signals are co nnected to the intc as follows. table 10-2. interrupt request signal map group line module signal 0 0 cpu with optional mpu and optional ocd sysreg compare 1 0 external interrupt controller eic 0 1 external interrupt controller eic 1 2 external interrupt controller eic 2 3 external interrupt controller eic 3 4 external interrupt controller eic 4 5 external interrupt controller eic 5 6 external interrupt controller eic 6 7 external interrupt controller eic 7 8 real time counter rtc 9 power manager pm 2 0 general purpose input/ou tput controller gpio 0 1 general purpose input/ou tput controller gpio 1 2 general purpose input/ou tput controller gpio 2 3 general purpose input/ou tput controller gpio 3 4 general purpose input/ou tput controller gpio 4 5 general purpose input/ou tput controller gpio 5 6 general purpose input/ou tput controller gpio 6 7 general purpose input/ou tput controller gpio 7 8 general purpose input/ou tput controller gpio 8 9 general purpose input/ou tput controller gpio 9 10 general purpose input/ou tput controller gpio 10 11 general purpose input/ou tput controller gpio 11 12 general purpose input/ou tput controller gpio 12 13 general purpose input/ou tput controller gpio 13
105 32072d?04/2011 at32uc3a3/a4 3 0 peripheral dma controller pdca 0 1 peripheral dma controller pdca 1 2 peripheral dma controller pdca 2 3 peripheral dma controller pdca 3 4 peripheral dma controller pdca 4 5 peripheral dma controller pdca 5 6 peripheral dma controller pdca 6 7 peripheral dma controller pdca 7 4 0 flash controller flashc 50 universal synchronous/asynchronous receiver/transmitter usart0 60 universal synchronous/asynchronous receiver/transmitter usart1 70 universal synchronous/asynchronous receiver/transmitter usart2 80 universal synchronous/asynchronous receiver/transmitter usart3 9 0 serial peripheral interface spi0 10 0 serial peripheral interface spi1 11 0 two-wire master interface twim0 12 0 two-wire master interface twim1 13 0 synchronous serial controller ssc 14 0 timer/counter tc00 1 timer/counter tc01 2 timer/counter tc02 15 0 analog to digital converter adc 16 0 timer/counter tc10 1 timer/counter tc11 2 timer/counter tc12 17 0 usb 2.0 otg interface usbb 18 0 sdram controller sdramc 19 0 audio bitstream dac abdac 20 0 mulitmedia card interface mci 21 0 advanced encryption standard aes table 10-2. interrupt request signal map
106 32072d?04/2011 at32uc3a3/a4 22 0 dma controller dmaca block 1 dma controller dmaca dstt 2 dma controller dmaca err 3 dma controller dmaca srct 4 dma controller dmaca tfr 26 0 memory stick interface msi 27 0 two-wire slave interface twis0 28 0 two-wire slave interface twis1 29 0 error code corrector hamming and reed solomon ecchrs table 10-2. interrupt request signal map
107 32072d?04/2011 at32uc3a3/a4 11. external interrupt controller (eic) rev: 2.4.0.0 11.1 features ? dedicated interrupt requ est for each interrupt ? individually maskable interrupts ? interrupt on rising or falling edge ? interrupt on high or low level ? asynchronous interrupts fo r sleep modes without clock ? filtering of interrupt lines ? maskable nmi interrupt ? keypad scan support 11.2 overview the external interrupt controller (eic) allows pins to be configured as external interrupts. each external interrupt has its own interrupt request and can be individually masked. each external interrupt can generate an interrupt on rising or falling edge, or high or low level. every interrupt input has a configurable filter to remove spikes from the interrupt source. every interrupt pin can also be configured to be asynchronous in order to wake up the part from sleep modes where the clk_sync clock has been disabled. a non-maskable interrupt (nmi) is also supported. this has the same properties as the other external interrupts, but is connected to the nmi request of the cpu, enabling it to interrupt any other interrupt mode. the eic can wake up the part from sleep modes without triggering an interrupt. in this mode, code execution starts from the instruction following the sleep instruction. the external interrupt controller has support for keypad scanning for keypads laid out in rows and columns. columns are driven by a separate set of scanning outputs, while rows are sensed by the external interrupt lines. the pressed key will trigger an interrupt, which can be identified through the user registers of the module.
108 32072d?04/2011 at32uc3a3/a4 11.3 block diagram figure 11-1. eic block diagram 11.4 i/o lines description 11.5 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 11.5.1 i/o lines the external interrupt pins (extintn and nmi) are multiplexed with i/o lines. to generate an external interrupt from an external source the s ource pin must be configured as an input pins by the i/o controller. it is also possible to trigger the interrupt by driving these pins from registers in the i/o controller, or another peripheral output connected to the same pin. 11.5.2 power management all interrupts are available in all sleep modes as long as the eic module is powered. however, in sleep modes where clk_sync is stopped, the interrupt must be configured to asynchronous mode. edge/level detector mask ir q n extintn nmi in t n level mode edge ie r id r ic r ctrl is r im r filter filter polarity control level mode edge asynchronus detector eic_w ake enable en dis ctrl clk_sync wake detect async prescaler shifter presc en scan pin scanm clk_rcsys table 11-1. i/o lines description pin name pin description type nmi non-maskable interrupt input extintn external interrupt input scanm keypad scan pin m output
109 32072d?04/2011 at32uc3a3/a4 11.5.3 clocks the clock for the eic bus interface (clk_eic) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. the filter and synchronous edge/level detector runs on a clock which is stopped in any of the sleep modes where the system rc oscillator is not running. th is clock is referred to as clk_sync. refer to the module configuration section at the end of this chapter for details. the keypad scan function ope rates on the system rc oscillator clock clk_rcsys. 11.5.4 interrupts the external interrupt request lines are connected to the interrupt controller. using the external interrupts requires the interrupt controller to be programmed first. using the non-maskable interrupt does not require the interrupt controller to be programmed. 11.5.5 debug operation the eic is frozen during debug operation, unless the ocd system keeps peripherals running during debug operation. 11.6 functional description 11.6.1 external interrupts the external interrupts are not enabled by default, allowing the proper interrupt vectors to be set up by the cpu before the interrupts are enabled. each external interrupt intn can be configured to prod uce an interrup t on rising or falling edge, or high or low level. external interrupts ar e configured by the mode, edge, and level regis- ters. each interrupt n has a bit intn in each of these registers. writing a zero to the intn bit in the mode register enables edge triggered interrupts, while writing a one to the bit enables level triggered interrupts. if intn is configured as an edge triggered interrupt, writing a zero to the intn bit in the edge register will cause the interrupt to be triggered on a falling edg e on extintn, while writing a one to the bit will cause the in terrupt to be triggered on a rising edge on extintn. if intn is configured as a leve l triggered interrupt, writing a zero to the intn bit in the level register will cause the interrupt to be triggered on a low level on extintn, while writing a one to the bit will cause the interrupt to be triggered on a high level on extintn. each interrupt has a corresponding bit in each of the interrupt control and status registers. writ- ing a one to the intn bit in the interrupt enabl e register (ier) enables the external interrupt from pin extintn to propagate from the eic to the interrupt controller, while writing a one to intn bit in the interrupt disable register (idr) disables this propagation. the interrupt mask register (imr) can be read to check which interrupts are enabled. when an interrupt triggers, the corresponding bit in th e interrupt status register (isr) will be set. this bit remains set until a one is written to the corresponding bit in the interrupt clear register (icr) or the interrupt is disabled. writing a one to the intn bit in the enable regist er (en) enables the external interrupt on pin extintn, while writing a one to intn bit in the disable register (dis) disables the external inter- rupt. the control register (ctrl) can be read to check which interrupts are enabled. if a bit in the ctrl register is set, but the corresponding bit in imr is not set, an interrupt will not propa-
110 32072d?04/2011 at32uc3a3/a4 gate to the interrupt controller. however, the corresponding bit in isr will be set, and eic_wake will be set. if the ctrl.intn bit is zero, then the correspondin g bit in isr will always be zero. disabling an external interrupt by writing to the dis.intn bit will cl ear the corresponding bit in isr. 11.6.2 synchronization and filtering of external interrupts in synchronous mode the pin value of the extintn pin is synchronized to clk_sync, so spikes shorter than one clk_sync cycle are not guaranteed to produce an interrupt. the syn- chronization of the extintn to clk_sync will delay the propagation of the interrupt to the interrupt controller by two cycles of clk_sync, see figure 11-2 on page 110 and figure 11-3 on page 110 for examples (filter off). it is also possible to apply a filter on extintn by writing a one to intn bit in the filter register. this filter is a majority voter, if the condition for an interrupt is true for more than one of the latest three cycles of clk_sync the interrupt will be se t. this will additionally delay the pr opagation of the interrupt to the interrupt controller by one or two cycles of clk_sync, see figure 11-2 on page 110 and figure 11-3 on page 110 for examples (filter on). figure 11-2. timing diagram, synchronous interr upts, high level or rising edge figure 11-3. timing diagram, synchrono us interrupts, low level or falling edge extintn/nmi clk_sync isr.intn: filter off isr.intn: filter on extintn/nmi clk_sync isr.intn: filter off isr.intn: filter on
111 32072d?04/2011 at32uc3a3/a4 11.6.3 non-maskable interrupt the nmi supports the same features as the external interrupts, and is accessed through the same registers. th e description in section 11.6.1 should be followed, accessing the nmi bit instead of the intn bits. the nmi is non-maskable within the cpu in the sense that it can interrupt any other execution mode. still, as for the other exte rnal interrupts, the actual nmi input can be enabled an d disabled by accessing the registers in the eic. 11.6.4 asynchronous interrupts each external inte rrupt can be made asynchronous by wr iting a one to intn in the async reg- ister. this will route the interrupt signal through the asynchronous path of the module. all edge interrupts will be interpreted as leve l interrupts and the f ilter is disabled. if an interrupt is config- ured as edge triggered interr upt in asynchronous mode, a zero in edge.intn will be interpreted as low level, and a one in edge.intn will be inte rpreted as high level. eic_wake will be set immediately after the source triggers the interrupt, while the correspond- ing bit in isr and the interrupt to the interrupt controller will be set on the next rising edge of clk_sync. please refere to figure 11-4 on page 111 for details. when clk_sync is stopped only asynchronous interrupts remain active, and any short spike on this interrupt will wake up the device . eic_wake will restart clk_sync and isr will be updated on the first rising edge of clk_sync. figure 11-4. timing diagram, asynchronous interrupts 11.6.5 wakeup the external interrupts can be used to wake up the part from sleep modes. the wakeup can be interpreted in two ways. if the corresponding bit in imr is one, then the execution starts at the interrupt handler for this interrupt. if the bit in imr is zero, then the execution starts from the next instruction after the sleep instruction. extintn/nmi clk_sync isr.intn: rising edge or high level eic_wake: rising edge or high level extintn/nmi clk_sync isr.intn: rising edge or high level eic_wake: rising edge or high level
112 32072d?04/2011 at32uc3a3/a4 11.6.6 keypad scan support the external interrupt controller also inclu des support for keypad scanning. the keypad scan feature is compatible with keypads organized as rows and columns, where a row is shorted against a column when a key is pressed. the rows should be connected to the external interrupt pins with pull-ups enabled in the i/o con- troller. these external interrupts should be enabled as low level or falling edge interrupts. the columns should be connected to the available scan pins. the i/o controller must be configured to let the required scan pins be controlled by the eic. unused external interrupt or scan pins can be left controlled by the i/o controller or other peripherals. the keypad scan function is enabled by writing scan.en to 1, which starts the keypad scan counter. the scan outputs are tri-stated, except scan[0], which is driven to zero. after 2 (scan.presc+1) rc clock cycles this pattern is left shifted, so that scan[1] is driven to zero while the other outputs are tri-stated. this sequence re peats infinitely, wrapping from the most signifi- cant scan pin to scan[0]. when a key is pressed, the pulled-up row is driven to zero by the column, and an external inter- rupt triggers. the scanning stops, and the software can then identify the key pressed by the interrupt status register and the scan.pins value. the scanning stops whenever there is an active interrupt request from the eic to the cpu. when the cpu clears the interrupt flags, scanning resumes.
113 32072d?04/2011 at32uc3a3/a4 11.7 user interface table 11-2. eic register memory map offset register register name access reset 0x000 interrupt enable register ier write-only 0x00000000 0x004 interrupt disable register idr write-only 0x00000000 0x008 interrupt mask register imr read-only 0x00000000 0x00c interrupt status register isr read-only 0x00000000 0x010 interrupt clear register icr write-only 0x00000000 0x014 mode register mode read/write 0x00000000 0x018 edge register edge read/write 0x00000000 0x01c level register level read/write 0x00000000 0x020 filter register filter read/write 0x00000000 0x024 test register test read/write 0x00000000 0x028 asynchronous register async read/write 0x00000000 0x2c scan register scan read/write 0x00000000 0x030 enable register en write-only 0x00000000 0x034 disable register dis write-only 0x00000000 0x038 control register ctrl read-only 0x00000000
114 32072d?04/2011 at32uc3a3/a4 11.7.1 interrupt enable register name: ier access type: write-only offset: 0x000 reset value: 0x00000000 ?intn: external interrupt n writing a zero to this bit has no effect. writing a one to this bit will set the corresponding bit in imr. ? nmi: non-maskable interrupt writing a zero to this bit has no effect. writing a one to this bit will set the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
115 32072d?04/2011 at32uc3a3/a4 11.7.2 interrupt disable register name: idr access type: write-only offset: 0x004 reset value: 0x00000000 ?intn: external interrupt n writing a zero to this bit has no effect. writing a one to this bit will clear the corresponding bit in imr. ? nmi: non-maskable interrupt writing a zero to this bit has no effect. writing a one to this bit will clear the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
116 32072d?04/2011 at32uc3a3/a4 11.7.3 interrupt mask register name: imr access type: read-only offset: 0x008 reset value: 0x00000000 ?intn: external interrupt n 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. this bit is cleared when the corresponding bit in idr is written to one. this bit is set when the corresponding bit in ier is written to one. ? nmi: non-maskable interrupt 0: the non-maskable in terrupt is disabled. 1: the non-maskable interrupt is enabled. this bit is cleared when the corresponding bit in idr is written to one. this bit is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
117 32072d?04/2011 at32uc3a3/a4 11.7.4 interrupt status register name: isr access type: read-only offset: 0x00c reset value: 0x00000000 ?intn: external interrupt n 0: an interrupt event has not occurred 1: an interrupt event has occurred this bit is cleared by writing a one to the corresponding bit in icr. ? nmi: non-maskable interrupt 0: an interrupt event has not occurred 1: an interrupt event has occurred this bit is cleared by writing a one to the corresponding bit in icr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
118 32072d?04/2011 at32uc3a3/a4 11.7.5 interrupt clear register name: icr access type: write-only offset: 0x010 reset value: 0x00000000 ?intn: external interrupt n writing a zero to this bit has no effect. writing a one to this bit will clear the corresponding bit in isr. ? nmi: non-maskable interrupt writing a zero to this bit has no effect. writing a one to this bit will clear the corresponding bit in isr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
119 32072d?04/2011 at32uc3a3/a4 11.7.6 mode register name: mode access type: read/write offset: 0x014 reset value: 0x00000000 ?intn: external interrupt n 0: the external interrupt is edge triggered. 1: the external interrupt is level triggered. ? nmi: non-maskable interrupt 0: the non-maskable interrupt is edge triggered. 1: the non-maskable interrupt is level triggered. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
120 32072d?04/2011 at32uc3a3/a4 11.7.7 edge register name: edge access type: read/write offset: 0x018 reset value: 0x00000000 ?intn: external interrupt n 0: the external interrupt triggers on falling edge. 1: the external interrupt triggers on rising edge. ? nmi: non-maskable interrupt 0: the non-maskable interrupt triggers on falling edge. 1: the non-maskable interrupt triggers on rising edge. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
121 32072d?04/2011 at32uc3a3/a4 11.7.8 level register name: level access type: read/write offset: 0x01c reset value: 0x00000000 ?intn: external interrupt n 0: the external interrupt triggers on low level. 1: the external interrupt triggers on high level. ? nmi: non-maskable interrupt 0: the non-maskable interrupt triggers on low level. 1: the non-maskable interrupt triggers on high level. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
122 32072d?04/2011 at32uc3a3/a4 11.7.9 filter register name: filter access type: read/write offset: 0x020 reset value: 0x00000000 ?intn: external interrupt n 0: the external interrupt is not filtered. 1: the external interrupt is filtered. ? nmi: non-maskable interrupt 0: the non-maskable interrupt is not filtered. 1: the non-maskable interrupt is filtered. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
123 32072d?04/2011 at32uc3a3/a4 11.7.10 test register name: test access type: read/write offset: 0x024 reset value: 0x00000000 ? testen: test enable 0: this bit disables external interrupt test mode. 1: this bit enables extern al interrupt test mode. ?intn: external interrupt n if testen is 1, the value written to this bit will be the value to the interrupt detector and the value on the pad will be igno red. ? nmi: non-maskable interrupt if testen is 1, the value written to this bit will be the value to the interrupt detector and the value on the pad will be igno red. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
124 32072d?04/2011 at32uc3a3/a4 11.7.11 asynchronous register name: async access type: read/write offset: 0x028 reset value: 0x00000000 ?intn: external interrupt n 0: the external interrupt is synchronized to clk_sync. 1: the external interrupt is asynchronous. ? nmi: non-maskable interrupt 0: the non-maskable interrupt is synchronized to clk_sync 1: the non-maskable interrupt is asynchronous. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
125 32072d?04/2011 at32uc3a3/a4 11.7.12 scan register name: scan access type: read/write offset: 0x2c reset value: 0x0000000 ? en 0: keypad scanning is disabled 1: keypad scanning is enabled ? presc prescale select for the keypad scan rate: scan rate = 2 (scan.presc+1) t rc the rc clock period can be found in the electrical characteristics section. ? pin the index of the currently active scan pin. writing to this bitfield has no effect. 31 30 29 28 27 26 25 24 - - - - - pin[2:0] 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - presc[4:0] 76543210 -------en
126 32072d?04/2011 at32uc3a3/a4 11.7.13 enable register name: en access type: write-only offset: 0x030 reset value: 0x00000000 ?intn: external interrupt n writing a zero to this bit has no effect. writing a one to this bit will enable the corresponding external interrupt. ? nmi: non-maskable interrupt writing a zero to this bit has no effect. writing a one to this bit will enable the non-maskable interrupt. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
127 32072d?04/2011 at32uc3a3/a4 11.7.14 disable register name: dis access type: write-only offset: 0x034 reset value: 0x00000000 ?intn: external interrupt n writing a zero to this bit has no effect. writing a one to this bit will disable the corresponding external interrupt. ? nmi: non-maskable interrupt writing a zero to this bit has no effect. writing a one to this bit will disable the non-maskable interrupt. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
128 32072d?04/2011 at32uc3a3/a4 11.7.15 control register name: ctrl access type: read-only offset: 0x038 reset value: 0x00000000 ?intn: external interrupt n 0: the corresponding external interrupt is disabled. 1: the corresponding external interrupt is enabled. ? nmi: non-maskable interrupt 0: the non-maskable in terrupt is disabled. 1: the non-maskable interrupt is enabled. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------nmi 76543210 int7 int6 int5 int4 int3 int2 int1 int0
129 32072d?04/2011 at32uc3a3/a4 11.8 module configuration the specific configuration for each eic instance is listed in the following tables.the module bus clocks listed here are connecte d to the system bus clocks. pleas e refer to the power manager chapter for details. table 11-3. module configuration feature eic number of external interrupts, including nmi 9 table 11-4. module clock name module name clock name eic clk_eic
130 32072d?04/2011 at32uc3a3/a4 12. flash controller (flashc) rev: 2.2.0.3 12.1 features ? controls flash block with dual read ports allowing staggered reads. ? supports 0 and 1 wait state bus access. ? allows interleaved burst reads for systems with one wait state, outputti ng one 32-bit word per clock cycle. ? 32-bit hsb interface for reads from flash array and writes to page buffer. ? 32-bit pb interface for issuing commands to and configuration of the controller. ? 16 lock bits, each protecting a region consisting of (total number of pages in the flash block / 16) pages. ? regions can be indi vidually protected or unprotected. ? additional protection of the boot loader pages. ? supports reads and writes of general-purpose nvm bits. ? supports reads and writes of additional nvm pages. ? supports device protection through a security bit. ? dedicated command for chip-erase, first erasing all on-chip volatile me mories before erasing flash and clearing security bit. ? interface to power manager for power- down of flash-blocks in sleep mode. 12.2 overview the flash controller (flashc) in terfaces a flash block with the 32-bit internal hsb bus. perfor- mance for uncached systems with high clock-frequency and one wait state is increased by placing words with sequential addresses in alternating flash subblocks. having one read inter- face per subblock allows them to be read in parallel. while data from one flash subblock is being output on the bus, the sequential address is being read from the ot her flash subblock and will be ready in the next clock cycle. the controller also manages the programming, erasing, locking and unlocking sequences with dedicated commands. 12.3 product dependencies 12.3.1 power manager the hflashc has two bus clocks connected: one high speed bus clock (clk_flashc_hsb) and one peripheral bus clock (clk_flashc_pb). these clocks are generated by the power manager. both clocks are tu rned on by default, but th e user has to ensure that clk_flashc_hsb is not turned off before reading the flash or writing the pagebuffer and that clk_flashc_pb is not turned of before accessing the flashc configuration and control registers. 12.3.2 interrupt controller the flashc interrupt lines are connected to internal sources of the interrupt controller. using flashc interrutps requires the interrupt controller to be programmed first.
131 32072d?04/2011 at32uc3a3/a4 12.4 functional description 12.4.1 bus interfaces the flashc has two bus interfaces, one high-speed bus (hsb) interface for reads from the flash array and writes to the page buffer, and one peripheral bus (pb) interface for writing com- mands and control to and reading status from the controller. 12.4.2 memory organization to maximize performance for high clock-frequency systems, flashc interfaces to a flash block with two read ports. the flash block has several parameters, given by the design of the flash block. refer to the ?memories? chapter for the device-specific values of the parameters. ? p pages ( flash_p ) ? w words in each page and in the page buffer ( flash_w ) ? pw words in total ( flash_pw ) ? f general-purpose fuse bits ( flash_f ) ? 1 security fuse bit ? 1 user page 12.4.3 user page the user page is an additional page, outside the regular flash array, that can be used to store various data, like calibration data and serial num bers. this page is not erased by regular chip erase. the user page can only be written and erased by proprietary commands. read accesses to the user page is performed just as any other read access to the flash. the address map of the user page is given in figure 12-1 . 12.4.4 read operations the flashc provides two different read modes: ? 0 wait state (0ws) for clock frequencies < (access time of the flash plus the bus delay) ? 1 wait state (1ws) for clock frequencies < (access time of the flash plus the bus delay)/2 higher clock frequencies that would require more wait states are not supported by the flash controller. the programmer can select the wait states required by writing to the fws field in the flash con- trol register (fcr). it is the responsibility of the prog rammer to select a nu mber of wait states compatible with the clock frequency and timing characteristics of the flash block. in 0ws mode, only one of the two flash read ports is accessed. the other flash read port is idle. in 1ws mode, both flash read ports are active. one read port reading the addressed word, and the other reading the next sequential word. if the clock frequency allows, the user should use 0ws mode, because this gives the lowest power consumption for low-frequency systems as on ly one flash read port is read. using 1ws mode has a power/performance ratio approaching 0ws mode as the clock frequency approaches twice the max frequency of 0ws mode. using two flash read ports use twice the power, but also give twice the performance.
132 32072d?04/2011 at32uc3a3/a4 the flash controller supports flash blocks with up to 2^21 word addresses, as displayed in figure 12-1 . reading the memory space between address pw and 2^21-1 returns an undefined result. the user page is permanently mapped to word address 2^21. figure 12-1. memory map for the flash memories 12.4.5 quick page read a dedicated command, quick page read (qpr), is provided to read all words in an addressed page. all bits in all words in this page are and?e d together, returning a 1-bi t result. this result is placed in the quick page read result (qprr) bi t in flash status register (fsr). the qpr command is useful to check that a page is in an erased state. the qpr instruction is much faster than performing the erased-page check using a regular software subroutine. 12.4.6 write page buffer operations the internal memory area reserved for the embedded flash can also be written through a write- only page buffer. the page buffer is addressed only by the address bits required to address w words (since the page buffer is word addressable) and thus wrap around within the internal memory area address space and appear to be repeated within it. when writing to the page buffer, the pagen field in the fcmd register is updated with the page number corresponding to page address of the latest word written into the page buffer. table 12-1. user page addresses memory type start address, byte sized size main array 0 pw words = 4 pw bytes user 0x0080 0000 128 words = 512 bytes 0 pw-1 pw 0x0080 0200 unused flash data array unused user page flash with extra page 0x0080 0000 all addresses are word addresses
133 32072d?04/2011 at32uc3a3/a4 the page buffer is also used for writes to the user page. write operations can be prevented by programming the memory protection unit of the cpu. writing 8-bit and 16-bit data to the page buffer is not allowed and may lead to unpredictable data corruption. page buffer write operations are performed with 2.2.0 wait states. writing to the page buffer can only change page buffer bits from one to zero, ie writing 0xaaaaaaaa to a page buffer location that has the value 0x00000000, will not change the page buffer value. the only way to change a bit from zero to one, is to reset the entire page buffer with the clear page buffer command. the page buffer is not automatically reset after a page write. the programmer should do this manually by issuing the clear page buffer flas h command. this can be done after a page write, or before the page buffer is loaded with data to be stored to the flash page. example: writing a word into word address 130 of a flash with 128 words in the page buffer. pagen will be updated with the va lue 1, and the word will be writ ten into word 2 in the page buffer. 12.4.7 writing words to a page that is not completely erased this can be used for eeprom emulation, i.e. writes with granularity of one word instead of an entire page. only words that are in an comp letely erased state (0xffffffff) can be changed. the procedure is as follows: 1. clear page buffer 2. write to the page buffer the result of the logical bitwise and operation between the contents of the flash page and the new data to write. only words that were in an erased state can be changed from the original page. 3. write page. 12.5 flash commands the flashc offers a command set to manage programming of the flash memory, locking and unlocking of regions, and full flash erasing. see chapter 12.8.3 for a complete list of commands. to run a command, the field cmd of the flash command register (fcmd) has to be written with the command number. as soon as the fcmd register is written, the frdy flag is automati- cally cleared. once the current command is complete, the frdy flag is automatically set. if an interrupt has been enabled by setting the bit frdy in fcr, the interrupt line of the flash control- ler is activated. all flash comm ands except for quick page re ad (qpr) will generate an interrupt request upon completion if frdy is set. after a command has been written to fcmd, the programming algorithm should wait until the command has been executed before attempting to read instructions or data from the flash or writing to the page buffer, as the flash will be busy. the waiting can be pe rformed either by poll- ing the flash status register (fsr) or by waiting for the flash ready interrupt. the command written to fcmd is initiated on the first clock cycle where the hsb bus interface in flashc is idle. the user must make sure that the access pattern to the flashc hsb interface contains an idle cycle so that the command is allowed to start. make sure that no bus masters such as dma controllers are performing endless burst transfers from the flash. also, make sure that the cpu does not perform endless burst transfers from flash. this is done by letting the cpu enter sleep mode after writing to fcmd, or by polling fsr for command completion. this polling will result in an access patt ern with idle hsb cycles.
134 32072d?04/2011 at32uc3a3/a4 all the commands are protected by the same keyword, which has to be written in the eight high- est bits of the fcmd register. writing fcmd wi th data that does not contain the correct key and/or with an invalid command has no effect on the flash memory; however, the proge flag is set in the flash status register (fsr). this flag is automatically cleared by a read access to the fsr register. writing a command to fcmd while another command is being executed has no effect on the flash memory; however, the proge flag is set in the flash status register (fsr). this flag is automatically cleared by a read access to the fsr register. if the current command writes or erases a page in a locked region, or a page protected by the bootprot fuses, the command has no effect on the flash memory; however, the locke flag is set in the fsr register. this fl ag is automatically cleared by a read access to the fsr register. 12.5.1 write/erase page operation flash technology requires that an erase must be done before programming. the entire flash can be erased by an erase all command. alternativ ely, pages can be individually erased by the erase page command. the user page can be written and erased usin g the mechanisms descr ibed in this chapter. after programming, the page can be locked to pr event miscellaneous write or erase sequences. locking is performed on a per-region basis, so locking a region locks all pages inside the region. additional protection is provided for the lowermost address space of the flash. this address space is allocated for the boot loader, and is protected both by the lock bit(s) corresponding to this address space, and the bootprot[2:0] fuses. data to be written are stored in an internal buffer called page buffer. the page buffer contains w words. the page buffer wraps around within the internal memory area address space and appears to be repeated by the number of pages in it. writing of 8-bit and 16-bit data to the page buffer is not allowed and may lead to unpredictable data corruption. data must be written to the page buffer before the programming command is written to the flash command register fcmd. the sequence is as follows: ? reset the page buffer with the clear page buffer command. ? fill the page buffer with the desired contents, using only 32-bit access. ? programming starts as soon as the programming key and the programming command are written to the flash command register. the pagen field in the flash command register (fcmd) must contain the address of the page to write. pagen is automatically updated when writing to the page buffer, but can also be written to directly. the frdy bit in the flash status register (fsr) is automatically cleared when the page write operation starts. ? when programming is completed, the bit frdy in the flash status register (fsr) is set. if an interrupt was enabled by setting the bit frdy in fcr, the interrupt line of the flash controller is set. two errors can be detected in the fsr register after a programming sequence: ? programming error: a bad keyword and/or an invalid command have been written in the fcmd register. ? lock error: the page to be programmed belongs to a locked region. a command must be executed to unlock the corresponding region before programming can start.
135 32072d?04/2011 at32uc3a3/a4 12.5.2 erase all operation the entire memory is erased if the erase all command (ea) is written to the flash command register (fcmd). erase all erases all bits in the flash array. the user page is not erased. all flash memory locations, the general-purpose fuse bi ts, and the security bit are erased (reset to 0xff) after an erase all. the ea command also ensures that all volatile me mories, such as register file and rams, are erased before the security bit is erased. erase all operation is allowed only if no regions are locked, and the bootprot fuses are pro- grammed with a region size of 0. thus, if at least one region is locked, the bit locke in fsr is set and the command is cancelled. if the bit locke has been written to 1 in fcr, the interrupt line rises. when the command is complete, the bit frdy bit in the flash status register (fsr) is set. if an interrupt has been enabled by setting the bit frdy in fcr, the interrupt line of the flash control- ler is set. two errors can be detected in the fsr register after issuing the command: ? programming error: a bad keyword and/or an invalid command have been written in the fcmd register. ? lock error: at least one lock region to be erased is protected, or bootprot is different from 0. the erase command has been refused and no page has been erased. a clear lock bit command must be executed previously to unlock the corresponding lock regions. 12.5.3 region lock bits the flash block has p pages, and these pages are grouped into 16 lock regions, each region containing p /16 pages. each region has a dedicated lock bit preventing writing and erasing pages in the region. after production, the device may have some regions locked. these locked regions are reserved for a boot or default applic ation. locked regions can be unlocked to be erased and then programmed with another application or other data. to lock or unlock a region, the commands lock region containing page (lp) and unlock region containing page (up) are provided. writing one of these commands, together with the number of the page whose region should be locked/unlocked, performs the desired operation. one error can be detected in the fsr register after issuing the command: ? programming error: a bad keyword and/or an invalid command have been written in the fcmd register. the lock bits are implemented using the lowest 16 general-purpose fuse bits. this means that lock bits can also be set/cleared using the commands for writing/erasing general-purpose fuse bits, see chapter 12.6. the general-purpose bit being in an erased (1) state means that the region is unlocked. the lowermost pages in the flash can additionally be protected by the bootprot fuses, see section 12.6 . 12.6 general-purpose fuse bits each flash block has a number of general-purpose fuse bits that the application programmer can use freely. the fuse bits can be written and erased using dedicated commands, and read
136 32072d?04/2011 at32uc3a3/a4 through a dedicated peripheral bus address. some of the general-purpose fuse bits are reserved for special purposes, and shou ld not be used for other functions.: the bootprot fuses protects the following address space for the boot loader: table 12-2. general-purpose fuses with special functions general- purpose fuse number name usage 15:0 lock region lock bits. 16 epfl external privileged fetch lock. used to prevent the cpu from fetching instructions from external memories when in privileged mode. this bit can only be changed when the security bit is cleared. the address range corresponding to external memories is device-specific, and not known to the flash controller. this fuse bit is simp ly routed out of the cpu or bus system, the flash controller does not treat this fuse in any special way, except that it can not be altered when the security bit is set. if the security bit is set, only an external jtag chip erase can clear epfl. no internal commands can alter epfl if the security bit is set. when the fuse is erased (i.e. "1"), the cpu can execute instructions fetched from external memories. when the fuse is programmed (i.e. "0"), instructions can not be executed from external memories. 19:17 bootprot used to select one of eight different bootloader sizes. pages included in the bootloader area can not be erased or programmed except by a jtag chip erase. bootprot can only be changed when the security bit is cleared. if the security bit is set, only an external jtag chip erase can clear bootprot, and thereby allow the pages protected by bootprot to be programmed. no internal commands can alter bootprot or the pages protected by bootprot if the security bit is set. table 12-3. boot loader area specified by bootprot bootprot pages protected by bootprot size of protected memory 7none 0 60-1 1kbyte 50-3 2kbyte 40-7 4kbyte 3 0-15 8kbyte 2 0-31 16kbyte 1 0-63 32kbyte 0 0-127 64kbyte
137 32072d?04/2011 at32uc3a3/a4 to erase or write a general-purpose fuse bit, the commands write general-purpose fuse bit (wgpb) and erase general-purpose fuse bit (e gpb) are provided. writing one of these com- mands, together with the number of the fuse to write/erase, performs the desired operation. an entire general-purpose fuse byte can be wr itten at a time by using the program gp fuse byte (pgpfb) instruction. a pgpfb to gp fuse byte 2 is not allowed if the flash is locked by the security bit. the pfb command is issued with a parameter in the pagen field: ? pagen[2:0] - byte to write ? pagen[10:3] - fuse value to write all general-purpose fuses can be erased by the erase all general-purpose fuses (eagp) com- mand. an eagp command is not allowed if the flash is locked by the security bit. two errors can be detected in the fsr register after issuing these commands: ? programming error: a bad keyword and/or an invalid command have been written in the fcmd register. ? lock error: a write or erase of any of the special-function fuse bits in table 12-3 was attempted while the flash is locked by the security bit. the lock bits are implemented using the lowest 16 general-purpose fuse bits. this means that the 16 lowest general-purpose fuse bits can also be written/erased using the commands for locking/unlocking regions, see section 12.5.3 . 12.7 security bit the security bit allows the entire chip to be locked from external jtag or other debug access for code security. the security bit can be written by a dedicated command, set security bit (ssb). once set, the only way to clear the security bit is through the jtag chip erase command. once the security bit is set, the following flash controller commands will be unavailable and return a lock error if attempted: ? write general-purpose fuse bit (w gpb) to bootprot or epfl fuses ? erase general-purpose fuse bit (egpb) to bootprot or epfl fuses ? program general-purpose fuse byte (pgpfb) of fuse byte 2 ? erase all general-purpose fuses (eagpf) one error can be detected in the fsr register after issuing the command: ? programming error: a bad keyword and/or an invalid command have been written in the fcmd register.
138 32072d?04/2011 at32uc3a3/a4 12.8 user interface 12.8.1 address map the following addresses are used by the flashc. all offsets are relative to the base address allocated to the flash controller. (*) the value of the lock bits is dependent of their programmed state. all other bits in fsr are 0. all bits in fgpfr and fcfr are dependent on the programmed state of the fuses they map to. any bits in these registers not mapped to a fuse read 0. table 12-4. flash controller register mapping offset register name access reset state 0x0 flash control register fcr r/w 0 0x4 flash command register fcmd r/w 0 0x8 flash status register fsr r/w 0 (*) 0xc flash general purpose fuse register hi fgpfrhi r na (*) 0x10 flash general purpose fuse register lo fgpfrlo r na (*)
139 32072d?04/2011 at32uc3a3/a4 12.8.2 flash control register name : fcr access type : read/write offset : 0x00 reset value : 0x00000000 ? frdy: flash ready interrupt enable 0: flash ready does not generate an interrupt. 1: flash ready generates an interrupt. ? locke: lock error interrupt enable 0: lock error does not generate an interrupt. 1: lock error generates an interrupt. ? proge: programming error interrupt enable 0: programming error does not generate an interrupt. 1: programming error generates an interrupt. ? fws: flash wait state 0: the flash is read with 0 wait states. 1: the flash is read with 1 wait state. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - fws - - proge locke - frdy
140 32072d?04/2011 at32uc3a3/a4 12.8.3 flash command register name : fcmd access type : read/write offset : 0x04 reset value : 0x00000000 the fcmd can not be written if the flash is in the process of performing a flash command. doing so will cause the fcr write to be ig nored, and the proge bit to be set. ? cmd: command this field defines the flash command. issuing any unused co mmand will cause the programming error flag to be set, and the corresponding interrupt to be requested if the proge bit in fcr is set. 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 pagen [15:8] 15 14 13 12 11 10 9 8 pagen [7:0] 76543210 -- cmd table 12-5. set of commands command value mnemonic no operation 0 nop write page 1 wp erase page 2 ep clear page buffer 3 cpb lock region containing given page 4 lp unlock region containing given page 5 up erase all 6 ea write general-purpose fuse bit 7 wgpb erase general-purpose fuse bit 8 egpb set security bit 9 ssb program gp fuse byte 10 pgpfb erase all gpfuses 11 eagpf quick page read 12 qpr
141 32072d?04/2011 at32uc3a3/a4 ?pagen: page number the pagen field is used to address a page or fuse bit for certai n operations. in order to simplify programming, the pagen field is automatically updated every time the page buffer is written to. for every page buffer write, the pagen field is updated with the page number of the address being written to. hardware automatically masks writes to the pagen field so that only bits representing valid page numbers can be writt en, all other bits in pagen are always 0. as an example, in a flash with 1024 pages (page 0 - page 1023), bits 15:10 will always be 0. ? key: write protection key this field should be written with the value 0xa5 to enable the command defined by the bits of t he register. if the field is wri tten with a different value, the write is not performed and no action is started. this field always reads as 0. write user page 13 wup erase user page 14 eup quick page read user page 15 qprup table 12-6. semantic of pagen field in different commands command pagen description no operation not used write page the number of the page to write clear page buffer not used lock region containing given page page number whose region should be locked unlock region containing given page page number whose region should be unlocked erase all not used write general-purpose fuse bit gpfuse # erase general-purpose fuse bit gpfuse # set security bit not used program gp fuse byte writed ata[7:0], byteaddress[2:0] erase all gp fuses not used quick page read page number write user page not used erase user page not used quick page read user page not used table 12-5. set of commands command value mnemonic
142 32072d?04/2011 at32uc3a3/a4 12.8.4 flash status register name : fsr access type : read/write offset : 0x08 reset value : 0x00000000 ? frdy: flash ready status 0: the flash controller is busy and the application must wait before running a new command. 1: the flash controller is ready to run a new command. ? locke: lock error status automatically cleared when fsr is read. 0: no programming of at least one locked lock region has happened since the last read of fsr. 1: programming of at least one locked lock region has happened since the last read of fsr. ? proge: programming error status automatically cleared when fsr is read. 0: no invalid commands and no bad keywords were written in the flash command register fcmd. 1: an invalid command and/or a bad keyword was/we re written in the flash command register fcmd. ? security: security bit status 0: the security bit is inactive. 1: the security bit is active. ? qprr: quick page read result 0: the result is zero, i.e. the page is not erased. 1: the result is one, i.e. the page is erased. 31 30 29 28 27 26 25 24 lock15 lock14 lock13 lock12 lock11 lock10 lock9 lock8 23 22 21 20 19 18 17 16 lock7 lock6 lock5 lock4 lock3 lock2 lock1 lock0 15 14 13 12 11 10 9 8 fsz ---- 76543210 - qprr security proge locke - frdy
143 32072d?04/2011 at32uc3a3/a4 ? fsz: flash size the size of the flash. not all device families will provide all flash sizes indicated in the table. ? lockx: lock region x lock status 0: the corresponding lock region is not locked. 1: the corresponding lock region is locked. table 12-7. flash size fsz flash size 0 32 kbyte 1 64 kbyte 2 128 kbyte 3 256 kbyte 4 384 kbyte 5 512 kbyte 6 768 kbyte 7 1024 kbyte
144 32072d?04/2011 at32uc3a3/a4 12.8.5 flash general purpose fuse register high name : fgpfrhi access type : read offset : 0x0c reset value : n/a this register is only used in syst ems with more t han 32 gp fuses. ? gpfxx: general purpose fuse xx 0: the fuse has a written/programmed state. 1: the fuse has an erased state. 31 30 29 28 27 26 25 24 gpf63 gpf62 gpf61 gpf60 gpf59 gpf58 gpf57 gpf56 23 22 21 20 19 18 17 16 gpf55 gpf54 gpf53 gpf52 gpf51 gpf50 gpf49 gpf48 15 14 13 12 11 10 9 8 gpf47 gpf46 gpf45 gpf44 gpf43 gpf42 gpf41 gpf40 76543210 gpf39 gpf38 gpf37 gpf36 gpf35 gpf34 gpf33 gpf32
145 32072d?04/2011 at32uc3a3/a4 12.8.6 flash general purpose fuse register low name : fgpfrlo access type : read offset : 0x10 reset value : n/a ? gpfxx: general purpose fuse xx 0: the fuse has a written/programmed state. 1: the fuse has an erased state. 31 30 29 28 27 26 25 24 gpf31 gpf30 gpf29 gpf28 gpf27 gpf26 gpf25 gpf24 23 22 21 20 19 18 17 16 gpf23 gpf22 gpf21 gpf20 gpf19 gpf18 gpf17 gpf16 15 14 13 12 11 10 9 8 gpf15 gpf14 gpf13 gpf12 gpf11 gpf10 gpf09 gpf08 76543210 gpf07 gpf06 gpf05 gpf04 gpf03 gpf02 gpf01 gpf00
146 32072d?04/2011 at32uc3a3/a4 12.9 fuses settings the flash block contains 32 general purpose fuses. these 32 fuses can be found in the flash general purpose fuse register low (fgpfrlo) of the flash controller (flashc). some of the fgpfrlo fuses have defined meanings outside the flashc and are described in this section. the general purpose fuses are set by a jtag chip erase. 12.9.1 flash general purpose fuse register low (fgpfrlo) ? boden: brown out detector enable ? bodhyst: brown out detector hystersis 0: the bod hysteresis is disabled 1: the bod hysteresis is enabled ? bodlevel: brown out detector trigger level this controls the voltage trigger level for the brown out detecto r. for value description refer to electrical characteristics c hapter. if the bodlevel is set higher than vddcore and enabled by fuse s, the part will be in constant reset. to recover from this situation, apply an external voltage on vddcore that is higher than the bod trigger level and disable the bod. ? lock, epfl, bootprot these are flash controller fuses an d are described in the flashc chapter. 12.9.2 default fuse value the devices are shipped with the fgpfrlo register value: 0xfff7ffff: ? gpf31 reserved for future use table 12-8. fgpfrlo register description 31 30 29 28 27 26 25 24 gpf31 gpf30 gpf29 boden bodhyst bodlevel[5:4] 23 22 21 20 19 18 17 16 bodlevel[3:0] bootprot epfl 15 14 13 12 11 10 9 8 lock[15:8] 76543210 lock[7:0] table 12-9. boden field description boden description 0x0 brown out detector (bod) disabled 0x1 bod enabled, bod reset enabled 0x2 bod enabled, bod reset disabled 0x3 bod disabled
147 32072d?04/2011 at32uc3a3/a4 ? gpf30 reserved for future use ? gpf29 reserved for future use ? boden fuses set to 0b11. bod is disabled. ? bodhyst fuse set to 0b1. the bod hystersis is enabled. ? bodlevel fuses set to 0b111111. this is the minimum vo ltage trigger level. bod will never trigger as this level is below the por level. ? bootprot fuses set to 0b011. the bootloader protected size is 8kbytes. ? epfl fuse set to 0b1. external privileged fetch is not locked. ? lock fuses set to 0b1111111111111111. no region locked. the devices are shipped with 2 bootloader configuration words in the flash user pages: at adress 808001f8h and 808001fch. see also the usb dfu bootloader user guide document. after the jtag chip erase command, the fgpfrlo register value is 0xffffffff. 12.10 serial number in the factory page each device has a unique 120 bits serial number located in the factory page and readable from address 0x80800204 to 0x80800212. 12.11 module configuration the specific configuration for the flashc instanc e is listed in the following tables.the module bus clocks listed here are connected to the system bus clocks according to the table in the power manager section. table 12-10. module configuration feature flash devices atuc3a3256s atuc3a3256 atuc3a4256s atuc3a4256 atuc3a3128s atuc3a3128 atuc3a4128s atuc3a4128 atuc3a364s atuc3a364 atuc3a464 atuc3a464 flash size 256kbytes 128kbytes 64kbytes number of pages 512 256 128 page size 512 bytes 512 bytes 512 bytes table 12-11. module clock name module name clock name clock name flashc clk_flashc_hsb clk_flashc_pb
148 32072d?04/2011 at32uc3a3/a4 13. hsb bus matrix (hmatrix) rev: 2.3.0.2 13.1 features ? user interface on peripheral bus ? configurable number of masters (up to sixteen) ? configurable number of slaves (up to sixteen) ? one decoder for each master ? ? programmable arbitration for each slave ? round-robin ? fixed priority ? programmable default master for each slave ? no default master ? last accessed default master ? fixed default master ? one cycle latency for the first access of a burst ? zero cycle latency for default master ? one special function register for each slave (not dedicated) 13.2 overview the bus matrix implements a multi-layer bus structure, that enables parallel access paths between multiple high speed bus (hsb) masters and slaves in a system, thus increasing the overall bandwidth. the bus matrix interconnects up to 16 hsb masters to up to 16 hsb slaves. the normal latency to connect a master to a slave is one cycle except for the default master of the accessed slave which is connected directly (zero cycle latency). the bus matrix provides 16 special function registers (sfr) that allow the bus matrix to support application specific features. 13.3 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 13.3.1 clocks the clock for the hmatrix bus interface (clk_hmatrix) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to disable the hmatrix before disabling the clock, to avoid freezing the hmatrix in an undefined state. 13.4 functional description 13.4.1 special bus granting mechanism the bus matrix provides some speculative bus granting techniques in order to anticipate access requests from some masters. this mechanism reduc es latency at first access of a burst or single transfer. this bus granting mechanism sets a different default master for every slave.
149 32072d?04/2011 at32uc3a3/a4 at the end of the current access, if no other re quest is pending, the slave remains connected to its associated default master. a slave can be as sociated with three kinds of default masters: no default master, last access master and fixed default master. 13.4.1.1 no default master at the end of the current access, if no other request is pending, the slave is disconnected from all masters. no default ma ster suits low-power mode. 13.4.1.2 last access master at the end of the current access, if no other re quest is pending, the slave remains connected to the last master that performed an access request. 13.4.1.3 fixed default master at the end of the current access, if no other r equest is pending, the slave connects to its fixed default master. unlike last access master, the fixed master does not change unless the user modifies it by a software action (field fixed_defmstr of the related scfg). to change from one kind of default master to another, the bus matrix user interface provides the slave configuration registers, one for each slave, that set a default master for each slave. the slave configuration register contains two fields: defmstr_type and fixed_defmstr. the 2-bit defmstr_type field selects the default mast er type (no default, last access master, fixed default master), whereas the 4-bit fixed_defmstr field selects a fixed default master pro- vided that defmstr_type is set to fixed default master. please refer to the bus matrix user interface description. 13.4.2 arbitration the bus matrix provides an arbitration mechanism that reduces latency when conflict cases occur, i.e. when two or more masters try to access the same slave at the same time. one arbiter per hsb slave is provided, thus ar bitrating each slave differently. the bus matrix provides the user with the possibility of choosing between 2 arbitration types for each slave: 1. round-robin arbitration (default) 2. fixed priority arbitration this choice is made via the field arbt of the slave configuration registers (scfg). each algorithm may be complemented by selecting a default master configuration for each slave. when a re-arbitration must be done, specific conditions apply. see section 13.4.2.1 ?arbitration rules? on page 149 . 13.4.2.1 arbitration rules each arbiter has the ability to arbitrate between two or more different master requests. in order to avoid burst breaking and also to provide the maximum throughput for slave interfaces, arbitra- tion may only take place during the following cycles: 1. idle cycles: when a slave is not connected to any master or is connected to a master which is not currently accessing it. 2. single cycles: when a slave is currently doing a single access.
150 32072d?04/2011 at32uc3a3/a4 3. end of burst cycles: when the current cycle is the last cycle of a burst transfer. for defined length burst, predicted end of burst matches the size of the transfer but is man- aged differently for undefined length burst. 4. slot cycle limit: when the slot cycle counte r has reached the limit value indicating that the current master access is too long and must be broken. ? undefined length burst arbitration in order to avoid long slave handling during unde fined length bursts (incr), the bus matrix pro- vides specific logic in order to re-arbitrate before the end of the incr transfer. a predicted end of burst is used as a defined length burst transfer and can be selected from among the following five possibilities: 1. infinite: no predicted end of burst is gen erated and therefore i ncr burst transfer will never be broken. 2. one beat bursts: predicted end of burst is generated at each single transfer inside the incp transfer. 3. four beat bursts: predicted end of burst is generated at the end of each four beat boundary inside incr transfer. 4. eight beat bursts: predicted end of burst is generated at the end of each eight beat boundary inside incr transfer. 5. sixteen beat bursts: predicted end of burst is generated at the end of each sixteen beat boundary inside incr transfer. this selection can be done through the field ulbt of the master configuration registers (mcfg). ? slot cycle limit arbitration the bus matrix contains specific logic to break long accesses, such as very long bursts on a very slow slave (e.g., an external low speed memory). at the beginning of the burst access, a counter is loaded with the value previously written in the slot_cycle field of the related slave configuration register (scfg) and decreased at each clock cycle. when the counter reaches zero, the arbiter has the ability to re-arbitrate at the end of the current byte, half word or word transfer. 13.4.2.2 round-robin arbitration this algorithm allows the bus matrix arbiters to dispatch the requests from different masters to the same slave in a round-robin manner. if two or more master requests arise at the same time, the master with the lowest number is first serviced, then the others are serviced in a round-robin manner. there are three round-robin algorithms implemented: 1. round-robin arbitration without default master 2. round-robin arbitration with last default master 3. round-robin arbitration with fixed default master ? round-robin arbitration without default master this is the main algorithm used by bus matrix arbiters. it allows the bus matrix to dispatch requests from different masters to the same slave in a pure round-robin manner. at the end of
151 32072d?04/2011 at32uc3a3/a4 the current access, if no other request is pending, the slave is disconnected from all masters. this configuration incurs one latency cycle for the first access of a burst. arbitration without default master can be used for masters that perform significant bursts. ? round-robin arbitration with last default master this is a biased round-robin algorithm used by bus matrix arbiters. it allows the bus matrix to remove the one late ncy cycle for the last master that acce ssed the slave. in fact, at the end of the current transfer, if no other master request is pending, the slave remains connected to the last master that performed the access. other non priv ileged masters still get one latency cycle if they want to access the same slave. this technique can be used for masters that mainly perform single accesses. ? round-robin arbitration with fixed default master this is another biased round-robin algorithm. it a llows the bus matrix arbiters to remove the one latency cycle for the fixed default master per slav e. at the end of the current access, the slave remains connected to its fixed default master. every request attempted by this fixed default mas- ter will not cause any latency whereas other non privileged masters w ill still get one latency cycle. this technique can be used for masters that mainly perform single accesses. 13.4.2.3 fixed priority arbitration this algorithm allows the bus matrix arbiters to dispatch the requests from different masters to the same slave by using the fixed priority defined by the user. if two or more master requests are active at the same time, the master with the highest priority number is serviced first. if two or more master requests with the same priority are active at the same time, the master with the highest number is serviced first. for each slave, the priority of each master may be defined through the priority registers for slaves (pras and prbs). 13.4.3 slave and master assignation the index number assigned to bus matrix slav es and masters are described in memories chapter.
152 32072d?04/2011 at32uc3a3/a4 13.5 user interface table 13-1. hmatrix register memory map offset register name access reset value 0x0000 master configuration register 0 mcfg0 read/write 0x00000002 0x0004 master configuration register 1 mcfg1 read/write 0x00000002 0x0008 master configuration register 2 mcfg2 read/write 0x00000002 0x000c master configuration register 3 mcfg3 read/write 0x00000002 0x0010 master configuration register 4 mcfg4 read/write 0x00000002 0x0014 master configuration register 5 mcfg5 read/write 0x00000002 0x0018 master configuration register 6 mcfg6 read/write 0x00000002 0x001c master configuration register 7 mcfg7 read/write 0x00000002 0x0020 master configuration register 8 mcfg8 read/write 0x00000002 0x0024 master configuration register 9 mcfg9 read/write 0x00000002 0x0028 master configuration register 10 mcfg10 read/write 0x00000002 0x002c master configuration regi ster 11 mcfg11 read/write 0x00000002 0x0030 master configuration register 12 mcfg12 read/write 0x00000002 0x0034 master configuration register 13 mcfg13 read/write 0x00000002 0x0038 master configuration register 14 mcfg14 read/write 0x00000002 0x003c master configuration regi ster 15 mcfg15 read/write 0x00000002 0x0040 slave configuration register 0 scfg0 read/write 0x00000010 0x0044 slave configuration register 1 scfg1 read/write 0x00000010 0x0048 slave configuration register 2 scfg2 read/write 0x00000010 0x004c slave configuration register 3 scfg3 read/write 0x00000010 0x0050 slave configuration register 4 scfg4 read/write 0x00000010 0x0054 slave configuration register 5 scfg5 read/write 0x00000010 0x0058 slave configuration register 6 scfg6 read/write 0x00000010 0x005c slave configuration register 7 scfg7 read/write 0x00000010 0x0060 slave configuration register 8 scfg8 read/write 0x00000010 0x0064 slave configuration register 9 scfg9 read/write 0x00000010 0x0068 slave configuration register 10 scfg10 read/write 0x00000010 0x006c slave configuration register 11 scfg11 read/write 0x00000010 0x0070 slave configuration register 12 scfg12 read/write 0x00000010 0x0074 slave configuration register 13 scfg13 read/write 0x00000010 0x0078 slave configuration register 14 scfg14 read/write 0x00000010 0x007c slave configuration register 15 scfg15 read/write 0x00000010 0x0080 priority register a for slave 0 pras0 read/write 0x00000000 0x0084 priority register b for slave 0 prbs0 read/write 0x00000000 0x0088 priority register a for slave 1 pras1 read/write 0x00000000
153 32072d?04/2011 at32uc3a3/a4 0x008c priority register b for slave 1 prbs1 read/write 0x00000000 0x0090 priority register a for slave 2 pras2 read/write 0x00000000 0x0094 priority register b for slave 2 prbs2 read/write 0x00000000 0x0098 priority register a for slave 3 pras3 read/write 0x00000000 0x009c priority register b for slave 3 prbs3 read/write 0x00000000 0x00a0 priority register a for slave 4 pras4 read/write 0x00000000 0x00a4 priority register b for slave 4 prbs4 read/write 0x00000000 0x00a8 priority register a for slave 5 pras5 read/write 0x00000000 0x00ac priority register b for slave 5 prbs5 read/write 0x00000000 0x00b0 priority register a for slave 6 pras6 read/write 0x00000000 0x00b4 priority register b for slave 6 prbs6 read/write 0x00000000 0x00b8 priority register a for slave 7 pras7 read/write 0x00000000 0x00bc priority register b for slave 7 prbs7 read/write 0x00000000 0x00c0 priority register a for slave 8 pras8 read/write 0x00000000 0x00c4 priority register b for slave 8 prbs8 read/write 0x00000000 0x00c8 priority register a for slave 9 pras9 read/write 0x00000000 0x00cc priority register b for slave 9 prbs9 read/write 0x00000000 0x00d0 priority register a for slave 10 pras10 read/write 0x00000000 0x00d4 priority register b for slave 10 prbs10 read/write 0x00000000 0x00d8 priority register a for slave 11 pras11 read/write 0x00000000 0x00dc priority register b for slave 11 prbs11 read/write 0x00000000 0x00e0 priority register a for slave 12 pras12 read/write 0x00000000 0x00e4 priority register b for slave 12 prbs12 read/write 0x00000000 0x00e8 priority register a for slave 13 pras13 read/write 0x00000000 0x00ec priority register b for slave 13 prbs13 read/write 0x00000000 0x00f0 priority register a for slave 14 pras14 read/write 0x00000000 0x00f4 priority register b for slave 14 prbs14 read/write 0x00000000 0x00f8 priority register a for slave 15 pras15 read/write 0x00000000 0x00fc priority register b for slave 15 prbs15 read/write 0x00000000 0x0110 special function register 0 sfr0 read/write ? 0x0114 special function register 1 sfr1 read/write ? 0x0118 special function register 2 sfr2 read/write ? 0x011c special function register 3 sfr3 read/write ? 0x0120 special function register 4 sfr4 read/write ? 0x0124 special function register 5 sfr5 read/write ? 0x0128 special function register 6 sfr6 read/write ? table 13-1. hmatrix register memory map (continued) offset register name access reset value
154 32072d?04/2011 at32uc3a3/a4 0x012c special function register 7 sfr7 read/write ? 0x0130 special function register 8 sfr8 read/write ? 0x0134 special function register 9 sfr9 read/write ? 0x0138 special function register 10 sfr10 read/write ? 0x013c special function register 11 sfr11 read/write ? 0x0140 special function register 12 sfr12 read/write ? 0x0144 special function register 13 sfr13 read/write ? 0x0148 special function register 14 sfr14 read/write ? 0x014c special function register 15 sfr15 read/write ? table 13-1. hmatrix register memory map (continued) offset register name access reset value
155 32072d?04/2011 at32uc3a3/a4 13.5.1 master configuration registers name: mcfg0...mcfg15 access type: read/write offset: 0x00 - 0x3c reset value: 0x00000002 ? ulbt: undefined length burst type 0: infinite length burst no predicted end of burst is generated and therefore i ncr bursts coming from this master cannot be broken. 1: single access the undefined length burst is treated as a su ccession of single accesses, allowing re-a rbitration at each beat of the incr burs t. 2: four beat burst the undefined length burst is split into a four-beat bu rst, allowing re-arbitration at each four-beat burst end. 3: eight beat burst the undefined length burst is split into an eight-beat bu rst, allowing re-arbitration at each eight-beat burst end. 4: sixteen beat burst the undefined length burst is split into a sixteen-beat bu rst, allowing re-arbitration at each sixteen-beat burst end. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????? ulbt
156 32072d?04/2011 at32uc3a3/a4 13.5.2 slave configuration registers name: scfg0...scfg15 access type: read/write offset: 0x40 - 0x7c reset value: 0x00000010 ? arbt: arbitration type 0: round-robin arbitration 1: fixed priority arbitration ? fixed_defmstr: fixed default master this is the number of the default master for this slave. only used if defmstr_type is 2. sp ecifying the number of a master which is not connected to the selected slave is equivalent to sett ing defmstr_type to 0. the size of this field depends on the number of masters. this size is log2(number of masters). ? defmstr_type: default master type 0: no default master at the end of the current slave access, if no other master r equest is pending, the slave is disconnected from all masters. this results in a one cycle latenc y for the first access of a burst transfer or for a single access. 1: last default master at the end of the current slave access, if no other master req uest is pending, the slave stays connected to the last master hav ing accessed it. this results in not having one cycle latency when the last master tries to access the slave again. 2: fixed default master at the end of the current slave access, if no other master request is pending, the slav e connects to the fixed master the numbe r that has been written in the fixed_defmstr field. this results in not having one cycle latency when the fixed master tries to access the slave again. ? slot_cycle: maximum number of allowed cycles for a burst when the slot_cycle limit is reached for a burst, it may be broken by another master trying to access this slave. this limit has been placed to avoid locking a very slow slave when very long bursts are used. this limit must not be very small. unreas onably small values break every burst and the bus matrix arbitrates without performing any data transfer. 16 cycles is a reasonable value for slot_cycle. 31 30 29 28 27 26 25 24 ???????arbt 23 22 21 20 19 18 17 16 ? ? fixed_defmstr defmstr_type 15 14 13 12 11 10 9 8 ???????? 76543210 slot_cycle
157 32072d?04/2011 at32uc3a3/a4 13.5.3 priority registers a for slaves name: pras0...pras15 access type: read/write offset: - reset value: 0x00000000 ? mxpr: master x priority fixed priority of master x for accessing the selected slave. the higher the number, the higher the priority. 31 30 29 28 27 26 25 24 ?? m7pr ?? m6pr 23 22 21 20 19 18 17 16 ?? m5pr ?? m4pr 15 14 13 12 11 10 9 8 ?? m3pr ?? m2pr 76543210 ?? m1pr ?? m0pr
158 32072d?04/2011 at32uc3a3/a4 13.5.4 priority registers b for slaves name: prbs0...prbs15 access type: read/write offset: - reset value: 0x00000000 ? mxpr: master x priority fixed priority of master x for accessing the selected slave. the higher the number, the higher the priority. 31 30 29 28 27 26 25 24 ? ? m15pr ? ? m14pr 23 22 21 20 19 18 17 16 ? ? m13pr ? ? m12pr 15 14 13 12 11 10 9 8 ? ? m11pr ? ? m10pr 76543210 ?? m9pr ?? m8pr
159 32072d?04/2011 at32uc3a3/a4 13.5.5 special function registers name: sfr0...sfr15 access type: read/write offset: 0x110 - 0x115 reset value: - ? sfr: special function register fields those registers are not a hmatrix spec ific register. the field of those will be defined where they are used. 31 30 29 28 27 26 25 24 sfr 23 22 21 20 19 18 17 16 sfr 15 14 13 12 11 10 9 8 sfr 76543210 sfr
160 32072d?04/2011 at32uc3a3/a4 13.6 bus matrix connections accesses to unused areas returns an error result to the master requesting such an access. the bus matrix has the several masters and slaves. each master has its own bus and its own decoder, thus allowing a different memory mapping per master. the master number in the table below can be used to index the hmatrix cont rol registers. for example, hmatrix mcfg0 register is associated with the cpu data master interface. each slave has its own arbiter, thus allowing a different arbitration per slave. the slave number in the table below can be used to index the hmatrix control registers. for example, hmatrix scfg4 register is associated with the embedded cpu sram slave interface. table 13-2. high speed bus masters master 0 cpu data master 1 cpu instruction master 2 cpu sab master 3 pdca master 4 dmaca hsb master 1 master 5 dmaca hsb master 2 master 6 usbb dma table 13-3. high speed bus slaves slave 0 internal flash slave 1 hsb-pb bridge a slave 2 hsb-pb bridge b slave 3 aes slave 4 embedded cpu sram slave 5 usbb dpram slave 6 ebi slave 7 dmaca slave slave 8 hramc0 slave 9 hramc1
161 32072d?04/2011 at32uc3a3/a4 figure 13-1. hmatrix master / slave connections cpu data 0 cpu instruction 1 cpu sab 2 pdca 3 internal flash 0 hsb-pb bridge a 1 hsb-pb bridge b 2 aes 3 hmatrix slaves hmatrix masters embedded cpu sram 4 dmaca master 0 4 dmaca master 1 usbb dma 5 6 usb dpram ebi dmaca slave hramc0 hramc1 5 6 7 8 9
162 32072d?04/2011 at32uc3a3/a4 14. external bus interface (ebi) rev.: 1.7.0.1 14.1 features ? optimized for application memory space support ? integrates three external memory controllers: ? static memory controller (smc) ? sdram controller (sdramc) ? error corrected code (ecchrs) controller ? additional logic for nand flash/smartmedia tm and compactflash tm support ? nand flash support: 8-bit as well as 16-bit devices are supported ? compactflash support: attribute memory, common memory, i/o modes are supported but the signal _iois16 (i/o mode) is not handled. ? optimized external bu s:16-bit data bus ? up to 24-bit address bus, up to 8-mbytes addressable ? optimized pin multiplexing to redu ce latencies on external memories ? up to 6 chip selects, configurable assignment: ? static memory controll er on chip select 0 ? sdram controller or static memory controller on chip select 1 ? static memory controller on ch ip select 2, op tional nand flash support ? static memory controller on chip se lect 3, optional nand flash support ? static memory controller on chip select 4, opti onal compactflash tm support ? static memory controller on chip select 5, opti onal compactflash tm support 14.2 overview the external bus interface (ebi) is designed to ensure the successful data transfer between several external devices and the embedded memory controller of an 32-bit avr device. the static memory, sdram and ecchrs controllers are all featured external memory controllers on the ebi. these external memory controllers are capable of handling several types of external memory and peripheral devices, such as sram, prom, eprom, eeprom, flash, and sdram. the ebi also supports the compactflash and the nand flash/smartmedia protocols via inte- grated circuitry that greatly reduces the requirements for external components. furthermore, the ebi handles data transfers with up to six external devices, each assigned to six address spaces defined by the embedded memory controller. data transfers are performed through a 16-bit, an address bus of up to 23 bits, up to six chip select lines (ncs[5:0]), and several control pins that are generally multiplexed between the different external memory controllers.
163 32072d?04/2011 at32uc3a3/a4 14.3 block diagram figure 14-1. ebi block diagram hsb hmatrix ebi sdram controller static memory controller compact flash logic nand flash smartmedia logic ecchrs controller address decoders chip select assignor mux logic peripheral bus i/o controller data[15:0] nwe1 nwe0 nrd ncs[5:0] addr[23:0] cas ras sda10 sdwe sdck sdcke nandoe nandwe cfrnw cfce1 cfce2 nwait hsb-pb bridge intc sdramc_irq ecchrs_irq sfr registers
164 32072d?04/2011 at32uc3a3/a4 14.4 i/o lines description table 14-1. ebi i/o lines description pin name alternate name pin description type active level ebi common lines data[15:0] data bus i/o smc dedicated lines addr[1] smc address bus line 1 output addr[12] smc address bus line 12 output addr[15] smc address bus line 15 output addr[23:18] smc address bu s line [23:18] output ncs[0] smc chip select line 0 output low nwait smc external wait signal input low sdramc dedicated lines sdck sdram clock output sdcke sdram clock enable output high sdwe sdram write enable output low sda10 sdram address bus line 10 output low ras - cas row and column signal output low compactflash dedicated lines cfce1 - cfce2 compactflash chip enable output low cfrnw compactflash read not write signal output nand flash/smartmedia dedicated lines nandoe nand flash output enable output low nandwe nand flash write enable output low smc/sdramc shared lines ncs[1] ncs[1] sdcs0 smc chip select line 1 sdramc chip select line 0 output low addr[0] dqm0 addr[0]-nbs0 sdramc dqm1 smc address bus line 0 or byte select 1 output addr[11:2] addr[9:0] addr[11:2] sdramc address bus lines [9:0] smc address bus lines [11:2] output addr[14:13] addr[9:0] addr[14:13] sdramc address bus lines [12:11] smc address bus lines [14:13] output addr[16] ba0 addr[16] sdramc bank 0 smc address bus line 16 output
165 32072d?04/2011 at32uc3a3/a4 14.5 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 14.5.1 i/o lines the pins used for interfacing the compliant external devices may be multiplexed with i/o con- troller lines. the user must first configure the i/o controller to assign the ebi pins to their peripheral functions. 14.5.2 power management to prevent bus errors ebi operation must be terminated before entering sleep mode. 14.5.3 clocks a number of clocks can be selected as source for the ebi. the selected clock must be enabled by the power manager. the following clock sources are available: ? clk_ebi ? clk_sdramc ? clk_smc addr[17] ba1 addr[17] sdramc bank 1 smcaddress bus line 17 output smc/compactflash shared lines nrd nrd cfnoe smc read signal compactflash cfnoe output low nwe0 nwe0-nwe cfnwe smc write enable10 or write enable compactflash cfnwe output low ncs[4] ncs[4] cfcs[0] smc chip select line 4 compactflash chip select line 0 output low ncs[5] ncs[5] cfcs[1] smc chip select line 5 compactflash chip select line 1 output low smc/nand flash/smartme dia shared lines ncs[2] ncs[2] nandcs[0] smc chip select line 2 nandflash/smartmedia chip select line 0 output low ncs[3] ncs[3] nandcs[1] smc chip select line 3 nandflash/smartmedia chip select line 1 output low sdramc/smc/compactfl ash shared lines nwe1 dqm1/ nwe1-nbs1/ cfniord sdramc dqm1 smc write enable1 or byte select 1 compactflash cfniord output pin name alternate name pin description type active level
166 32072d?04/2011 at32uc3a3/a4 ? clk_ecchrs refer to table 14-2 on page 166 to configure those clocks. 14.5.4 interrupts the ebi interface has two interrupt lines connected to the interrupt controller: ? sdramc_irq: interrupt signal coming from the sdramc ? ecchrs_irq: interrupt signal coming from the ecchrs handling the ebi interrupt requires configuring the interrupt controller before configuring the ebi. 14.5.5 hmatrix the ebi interface is connected to the hmatrix special function register 6 (sfr6). the user must first write to this hmatrix.sf r6 to configure the ebi correctly. table 14-2. ebi clocks configuration clocks name clocks type type of the interfaced device sdram sram, prom, eprom, eeprom, flash nandflash smartmedia compactflash clk_ebi hsb x x x x clk_sdramc pb x clk_smc pb x x x clk_ecchrs pb x table 14-3. ebi special function register fields description sfr6 bit number bit name description [31:6] reserved 5cs5a 0 = chip select 5 (ncs[5]) is connect ed to a static memory device. for each access to the ncs[5] memory space, all related pins act as smc pins 1 = chip select 5 (ncs[5]) is connect ed to a compactflash device. for each access to the ncs[5] memory space, al l related pins act as compactflash pins 4cs4a 0 = chip select 4 (ncs[4]) is connect ed to a static memory device. for each access to the ncs[4] memory space, all related pins act as smc pins 1 = chip select 4 (ncs[4]) is connect ed to a compactflash device. for each access to the ncs[4] memory space, al l related pins act as compactflash pins 3cs3a 0 = chip select 3 (ncs[3]) is connect ed to a static memory device. for each access to the ncs[3] memory space, all related pins act as smc pins 1 = chip select 3 (ncs[3]) is connec ted to a nandflash or a smartmedia device. for each access to the ncs[3] me mory space, all related pins act as nandflash or smartmedia pins
167 32072d?04/2011 at32uc3a3/a4 14.6 functional description the ebi transfers data between the internal hsb bus (handled by the hmatrix) and the exter- nal memories or peripheral devices. it controls the waveforms and the parameters of the external address, data and control busses and is composed of the following elements: ? the static memory controller (smc) ? the sdram controller (sdramc) ? the ecchrs controller (ecchrs) ? a chip select assignment feature that assigns an hsb address space to the external devices ? a multiplex controller circuit that shares the pins between the different memory controllers ? programmable compactflash support logic ? programmable smartmedia and nand flash support logic 14.6.1 bus multiplexing the ebi offers a complete set of control signal s that share the 16-bit data lines, the address lines of up to 24 bits and the control signals through a multiplex logic operating in function of the memory area requests. multiplexing is specifically organized in or der to guarantee the maintenance of the address and output control lines at a stable state while no ex ternal access is being pe rformed. mult iplexing is also designed to respect the data float times defined in the memory controllers. furthermore, refresh cycles of the sdram are executed independently by the sdramc without delaying the other external memory controller accesses. 14.6.2 static memory controller for information on the static memory controller, refer to the static memory controller section. 14.6.3 sdram controller writing a one to the hmatrix.sfr6.cs1a bit enables the sdram logic. for information on the sdram contro ller, refer to the sdram section. 14.6.4 ecchrs controller for information on the ecchrs contro ller, refer to the ecchrs section. 2cs2a 0 = chip select 2 (ncs[2]) is connect ed to a static memory device. for each access to the ncs[2] memory space, all related pins act as smc pins 1 = chip select 2 (ncs[2]) is connec ted to a nandflash or a smartmedia device. for each access to the ncs[2] me mory space, all related pins act as nandflash or smartmedia pins 1cs1a 0 = chip select 1 (ncs[1]) is connect ed to a static memory device. for each access to the ncs[1] memory space, all related pins act as smc pins 1 = chip select 1 (ncs[1]) is connected to a sdram device. for each access to the ncs[1] memory space, al l related pins act as sdram pins 0 reserved table 14-3. ebi special function register fields description sfr6 bit number bit name description
168 32072d?04/2011 at32uc3a3/a4 14.6.5 compactflash support the external bus interface integrates circuitry that interfaces to compactflash devices. the compactflash logic is driven by the smc on the ncs[4] and/or ncs[5] address space. writing to the hmatrix.sfr6.cs4a and/or hm atrix.sfr6.cs5a bits the appropriate value enables this logic. access to an external compactflash device is then made by accessing the address space reserved to ncs[4] and/or ncs[5]. attribute memory, common memory, i/o modes are supported but the signals _iowr, _iois16 (i/o mode) are not handled. 14.6.5.1 i/o mode, common memory mode, attribute memory mode within the ncs[4] and/or ncs[5] address space, the current transfer address is used to distin- guish i/o mode, common memory mode andattribute memory mode. the different modes are accessed through a specific memory mapping as illustrated on figure 14-2 on page 168 . addr[23:21] bits of the transfer address are used to select the desired mode as described in table 14-4 on page 168 . figure 14-2. compactflash memory mapping note: the addr[22] i/o line is used to drive t he reg signal of the compactflash device. 14.6.5.2 cfce1 and cfce2 signals to cover all types of access, the smc must be al ternatively set to drive 8-bit data bus or 16-bit data bus. the odd byte access on the data[7:0] bus is only possible when the smc is config- table 14-4. compactflash mode selection addr[23:21] mode base address 000 attribute memory 001 i/o mode (write operations) 010 common memory 100 i/o mode (read operations) i/o mode space (read operations) common memory mode space at t ri but e memory mode space offset 0x0080 0000 offset 0x0040 0000 offset 0x0000 0000 cf address space i/o mode space (write operations) offset 0x0020 0000
169 32072d?04/2011 at32uc3a3/a4 ured to drive 8-bit memory devices on the corresponding ncs pin (ncs[4] or ncs[5]). the data bus width (dbw) field in the smc mode (mode) register of the ncs[4] and/or ncs[5] address space must be written as shown in table 14-5 on page 169 to enable the required access type. nbs1 and nbs0 are the byte selection signals from smc and are available when the smc is set in byte select mode on the corresponding chip select. the cfce1 and cfce2 waveforms are identical to the corresponding ncsx waveform. for details on these waveforms and timings, refer to the smc section. 14.6.5.3 read/write signals during read operations, in i/o mode, the compac tflash logic drives the read command signals of the smc on cfniord signal, while the cfnoe is deactivated. likewise, in common memory mode and attribute memory mode, the smc signals are driven on the cfnoe signal, while the cfniord is deactivated. figure 14-3 on page 170 demonstrates a schematic representation of this logic. during write operations, in all modes, the compactflash logic drives the write command signal of the smc on cfnwe signal. addtionnal external logic is required to drive _we and _iowr compact flash signals based on cfnwe. figure 14-3 on page 170 demonstrates a schematic representation of this logic. no external logic is required if i/o mode is not used (in this case, cnfwe signal can drive directly _we compact flash signal). attribute memory mode, common memory mode and i/o mode are supported by writing the address setup and hold time on the ncs[4] (and/or ncs[5]) chip select to the appropriate val- ues. for details on these signal waveforms, pleas e refer to the section: setup and hold cycles of the smc section. table 14-5. cfce1 and cfce2 truth table mode cfce2 cfce1 dbw comment smc access mode attribute memory nbs1 nbs0 16 bits access to even byte on data[7:0] byte select common memory nbs1 nbs0 16bits access to even byte on data[7:0] access to odd byte on data[15:8] byte select 1 0 8 bits access to odd byte on data[7:0] i/o mode nbs1 nbs0 16 bits access to even byte on data[7:0] access to odd byte on data[15:8] byte select 1 0 8 bits access to odd byte on data[7:0]
170 32072d?04/2011 at32uc3a3/a4 figure 14-3. compactflash read/write control signals 14.6.5.4 multiplexing of compactflash signals on ebi pins table 14-7 on page 170 and table on page 170 illustrate the multiplexi ng of the compactflash logic signals with other ebi signals on the ebi pins. the ebi pins in table 14-7 on page 170 are strictly dedicated to the compactflash interface as soon as the hmatrix.sfr6.cs4a and/or hmatrix.sfr6.cs5a bits is/are written. these pins must not be used to drive any other mem- ory devices. the ebi pins in table 14-8 on page 171 remain shared between all memory areas when the cor- responding compactflash interface is enabled (cs4a = 1 and/or cs5a = 1). table 14-6. compactflash mode selection mode base address cfnoe cfnwe cfniord attribute memory i/o mode (write operations) common memory nrd_noe nwr0_nwe 1 i/o mode (read operations) 1 1 nrd_noe a22 a23 smc nrd nwr0/nwe compact flash logic ebi 1 1 1 0 0 1 1 0 1 cfnoe cfnwe cfniord table 14-7. dedicated compactflash interface multiplexing pins compactflash signals ebi signals cs4a = 1 cs5a = 1 cs4a = 0 cs5a = 0 ncs[4] cfcs0 ncs[4] ncs[5] cfcs1 ncs[5]
171 32072d?04/2011 at32uc3a3/a4 14.6.5.5 application example figure 14-4 on page 171 illustrates an example of a comp actflash application. cfcs0 and cfrnw signals are not directly connected to the compactflash slot 0, but do control the direc- tion and the output enable of the buffers between the ebi and the compactflash device. the timing of the cfcs0 signal is identical to the ncs[4] signal. the cfrnw signal remains valid throughout the transfer, as does the address bus. the compactflash _wait signal is con- nected to the nwait input of the static memory controller. for details on these waveforms and timings, refer to the smc section. figure 14-4. compactflash applicatio n example with i/o mode table 14-8. shared compactflash interface mu ltiplexing pins access to compactflash device compactflash signals nrd cfnoe nwe0 cfnwe nwe1 cfniord cfrnw cfrnw ebi compactflash connector data[15:0] cfrnw ncs[4] pxx addr[10:0] addr[22] nrd nwe0 nwe1 cfce1 cfce2 nwait _wait _ce2 _ce1 _iowr _iord _we _oe _reg a[10:0] _cd2 _cd1 d[15:0] /oe /oe dir addr[21]
172 32072d?04/2011 at32uc3a3/a4 figure 14-5. compactflash application example without i/o mode 14.6.6 smartmedia and nand flash support the ebi integrates circuitry that interfac es to smartmedia and nand flash devices. the nand flash logic is driven by the static memory controller on th e ncs[2] (and/or ncs[3]) address space. writing to the hmatrix.sfr6.cs2a (and/or hmatrix.sfr6.cs3a) bit the appropriate value enables the nand flash logic. access to an external nand flash device is then made by accessing the address space reserved to ncs[2] (and/or ncs[3]). the nand flash logic drives the read and write command signals of the smc on the nandoe and nandwe signals when the ncs[2] (and/or ncs[3]) signal is active. nandoe and nandwe are invalidated as soon as the transfer address fails to lie in the ncs[2] (and/or ncs[3]) address space. see figure 14-6 on page 173 for more informations. for details on these waveforms, refer to the smc section. the smartmedia device is connected the same way as the nand flash device. ebi compactflash connector data[15:0] cfrnw ncs[4] pxx addr[10:0] addr[22] nrd nwe0 nwe1 cfce1 cfce2 nwait _wait _ce2 _ce1 _iowr _iord _we _oe _reg a[10:0] _cd2 _cd1 d[15:0] /oe /oe dir addr[21]
173 32072d?04/2011 at32uc3a3/a4 figure 14-6. nand flash signal multiplexing on ebi pins 14.6.6.1 nand flash signals the address latch enable and command latch enable signals on the nand flash device are driven by address bits addr[22] and addr[21] of the ebi address bus. the user should note that any bit on the ebi address bus can also be used for this purpose. the command, address or data words on the data bus of the nand flash dev ice are distinguished by using their address within the ncsx address space. the chip enable (ce) signal of the device and the ready/busy (r/b) signals are connected to i/o controller lines. the ce signal then remains asserted even when ncsx is not selected, preventing the device from returning to standby mode. figure 14-7. nand flash application example note: the external bus interfaces is also able to support 16-bits devices. smc nandflash logic ncs[2]/[3] nrd nwr0_nwe nandoe nandwe ebi ebi ncs[2/3] or i/o line i/o line data[7:0] addr[22] addr[21] ale cle ad[7:0] noe nwe ce r/b nandflash nandoe nandwe
174 32072d?04/2011 at32uc3a3/a4 14.7 application example 14.7.1 hardware interface note: 1. nwe1 enables upper byte writes. nwe0 enables lower byte writes. 2. nbs1 enables upper byte writes. nbs0 enables lower byte writes. table 14-9. ebi pins and external static devices connections pins name pins of the interfaced device 8-bit static device 2 x 8-bit static devices 16-bit static device controller smc data[7:0] d[7:0] d[7:0] d[7:0] data[15:0 ? d[15:8] d[15:8] addr[0] a[0] ? nbs0 (2) addr[1] a[1] a[0] a[0] addr[23:2] a[23:2] a[22:1] a[22:1] ncs[0] - ncs[5] cs cs cs nrd oe oe oe nwe0 we we (1) we nwe1 ? we (1) nbs1 (2) table 14-10. ebi pins and external devices connections pins name pins of the interfaced device sdram compact flash smart media or nand flash controller sdramc smc data[7:0] d[7:0] d[7:0] ad[7:0] data[15:8] d[15:8] d[15:8] ad[15:8] addr[0] dqm0 a[0] ? addr[1] ? a[1] ? addr[10:2] a[8:0] a[10:2] ? addr[11] a[9] ? ? sda10 a[10] ? ? addr[12] ? ? ? addr[14:13] a[12:11] ? ? addr[15] ? ? ? addr[16] ba0 ? ? addr[17] ba1 ? ? addr[20:18] ? ? ?
175 32072d?04/2011 at32uc3a3/a4 note: 1. not directly connected to the compactflash sl ot. permits the control of the bidirectional buffer between the ebi data bus a nd the compactflash slot. 2. any i/o controller line. 3. the cle and ale signals of the nand flash device may be driven by any address bit. for details, see section 14.6.6 . addr[21] ? ? cle (3) addr[22] ? reg ale (3) ncs[0] ? ? ? ncs[1] sdcs[0] ? ? ncs[2] ? ? ce0 ncs[3] ? ? ce1 ncs[4] ? cfcs0 (1) ? ncs[5] ? cfcs1 (1) ? nandoe ? ? oe nandwe ? ? we nrd ? oe ? nwe0 ? we ? nwe1 dqm1 ior ? cfrnw ? cfrnw (1) ? cfce1 ? ce1 ? cfce2 ? ce2 ? sdck clk ? ? sdcke cke ? ? ras ras ? ? cas cas ? ? sdwe we ? ? nwait ? wait ? pxx (2) ? cd1 or cd2 ? pxx (2) ??rdy table 14-10. ebi pins and external devices connections (continued) pins name pins of the interfaced device sdram compact flash smart media or nand flash controller sdramc smc
176 32072d?04/2011 at32uc3a3/a4 14.7.2 connection examples figure 14-8 on page 176 shows an example of connections between the ebi and external devices. figure 14-8. ebi connections to memory devices ebi data[15:0] ras cas sdck sdcke sdwe addr[0] nwe1 nrd nwe0 sdram 2mx8 d[7:0] cs clk cke we ras cas dqm a[9:0] a[10] a[11] ba0 ba1 sdram 2mx8 d[7:0] cs clk cke we ras cas dqm a[9:0] a[10] a[11] ba0 ba1 data[7:0] data[15:8] addr[11:2] sda10 addr[13] addr[16] addr[17] addr[11:2] sda10 addr[13] addr[16] addr[17] sdck sdcke sdwe ras cas addr[0] sdck sdcke sdwe ras cas nwe1 sda10 addr[17:1] ncs[1] sram 128kx8 we oe cs d[7:0] a[16:0] sram 128kx8 we oe cs d[7:0] a[16:0] data[7:0] data[15:8] addr[17:1] addr[17:1] ncs[0] ncs[0] ncs[0] nrd nrd nwe0 nwe1
177 32072d?04/2011 at32uc3a3/a4 15. static memory controller (smc) rev. 1.0.6.5 15.1 features ? 6 chip selects available ? 16-mbytes address space per chip select ? 8- or 16-bit data bus ? word, halfword, byte transfers ? byte write or byte select lines ? programmable setup, pulse and hold ti me for read signals per chip select ? programmable setup, pulse and hold ti me for write signal s per chip select ? programmable data float time per chip select ? compliant with lcd module ? external wait request ? automatic switch to slow clock mode ? asynchronous read in page mode supporte d: page size ranges from 4 to 32 bytes 15.2 overview the static memory controller (smc) generates the signals that control the access to the exter- nal memory devices or peripheral devices. it has 6 chip selects and a 24-bit address bus. the 16-bit data bus can be configured to interface with 8-16-bit external devices. separate read and write control signals allow for direct memory and peripheral interfacing. read and write signal waveforms are fully parametrizable. the smc can manage wait requests from external devices to extend the current access. the smc is provided with an automatic slow clock mode. in slow clock mode, it switches from user- programmed waveforms to slow-rate specific waveforms on read and write signals. the smc supports asynchronous burst read in page mode access for page size up to 32 bytes.
178 32072d?04/2011 at32uc3a3/a4 15.3 block diagram figure 15-1. smc block diagram (ad_msb=23) 15.4 i/o lines description 15.5 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. smc chip select hmatrix power manager clk_smc smc i/o controller ncs[5:0] nrd nwe0 addr[0] nwe1 addr[1] addr[ad_msb:2] data[15:0] nwait user interface peripheral bus ncs[5:0] nrd nwr0/nwe a0/nbs0 nwr1/nbs1 a1/nwr2/nbs2 a[ad_msb:2] d[15:0] nwait ebi mux logic table 15-1. i/o lines description pin name pin description type active level ncs[5:0] chip select lines output low nrd read signal output low nwr0/nwe write 0/write enable signal output low a0/nbs0 address bit 0/byte 0 select signal output low nwr1/nbs1 write 1/byte 1 select signal output low a[23:2] address bus output d[15:0] data bus input/output nwait external wait signal input low
179 32072d?04/2011 at32uc3a3/a4 15.5.1 i/o lines the smc signals pass through the external bus in terface (ebi) module where they are multi- plexed. the user must first configure the i/o controller to assign the ebi pins corresponding to smc signals to their peripheral function. if the i/o lines of the ebi corresponding to smc signals are not used by the application, they can be us ed for other purposes by the i/o controller. 15.5.2 clocks the clock for the smc bus interface (clk_smc) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to disable the smc before disabling the clock, to avoid freezing the smc in an undefined state. 15.6 functional description 15.6.1 application example figure 15-2. smc connections to st atic memory devices 15.6.2 external memory mapping the smc provides up to 24 address lines, a[23:0] . this allows each chip select line to address up to 16mbytes of memory. if the physical memory device connected on one chip select is smaller than 16mbytes, it wraps around and appears to be repeated within this space. the smc correctly handles any valid access to the memory devi ce within the page (see figure 15-3 on page 180 ). a[23:0] is only significant for 8-bit memo ry, a[23:1] is used for 16-bit memory23. 128k x 8 sram d0-d7 cs oe we a0-a16 128k x 8 sram d0-d7 cs oe we a0-a16 d0-d15 nwr1/nbs1 a0/nbs0 nwr0/nwe ncs0 ncs2 ncs1 ncs3 ncs5 ncs4 nrd nrd a2-a18 static memory controller nwr0/nwe nwr1/nbs1 d8-d15 d0-d7 a2-a18 a2-a18
180 32072d?04/2011 at32uc3a3/a4 figure 15-3. memory connections for six external devices 15.6.3 connection to external devices 15.6.3.1 data bus width a data bus width of 8 or 16 bits can be selected for each chip select. this option is controlled by the data bus width field in the mode register (mode.dbw) for the corresponding chip select. figure 15-4 on page 180 shows how to connect a 512k x 8-bit memory on ncs2. figure 15-5 on page 181 shows how to connect a 512k x 16-bit memory on ncs2. 15.6.3.2 byte write or byte select access each chip select with a 16-bit data bus can operate with one of two different types of write access: byte write or byte select access. this is controlled by the byte access type bit in the mode register (mode.bat) for th e corresponding chip select. figure 15-4. memory connection for an 8-bit data bus ncs[0] - ncs[5] nrd nwe a[ad_msb:0] d[15:0] smc ncs5 ncs4 ncs3 ncs2 ncs1 ncs0 8 or 16 memory enable memory enable memory enable memory enable memory enable memory enable output enable write enable a[ad_msb:0] d[15:0] or d[7:0] smc a0 nwe nrd ncs[2] a0 write enable output enable memory enable d[7:0] d[7:0] a[18:2] a[18:2] a1 a1
181 32072d?04/2011 at32uc3a3/a4 figure 15-5. memory connection for a 16-bit data bus ?byte write access the byte write access mode supports one byte write signal per byte of the data bus and a single read signal. note that the smc does not allow boot in byte write access mode. ? for 16-bit devices: the smc provides nwr0 and nwr1 write signals for respectively byte0 (lower byte) and byte1 (upper byte) of a 16-bit bus. one single read signal (nrd) is provided. the byte write access mode is used to connect two 8-bit devices as a 16-bit memory. the byte write optio n is illustrated on figure 15-6 on page 182 . ?byte select access in this mode, read/write operations can be enabled /disabled at a byte level. one byte select line per byte of the data bus is provided. one nrd and one nwe signal control read and write. ? for 16-bit devices: the smc provides nbs0 and nbs1 selection signals for respectively byte0 (lower byte) and byte1 (upper byte) of a 16-bit bus. the byte select access is used to connect one 16-bit device. smc nbs0 nwe nrd ncs[2] low byte enable write enable output enable memory enable nbs1 high byte enable d[15:0] d[15:0] a[19:2] a[18:1] a[0] a1
182 32072d?04/2011 at32uc3a3/a4 figure 15-6. connection of two 8-bit devices on a 16-bit bus: byte write option ?signal multiplexing depending on the mode.bat bit, only the write si gnals or the byte select signals are used. to save i/os at the external bus interface, control signals at the smc interface are multiplexed. for 16-bit devices, bit a0 of address is unused. when byte select option is selected, nwr1 is unused. when byte write option is selected, nbs0 to nbs1 are unused. table 15-3. smc multiplexed signal translation 15.6.4 standard read and write protocols in the following sections, the byte access type is not considered. byte select lines (nbs0 to nbs1) always have the same timing as the address bus (a). nwe represents either the nwe signal in byte select access type or one of the byte write lines (nwr0 to nwr1) in byte write smc a1 nwr0 nrd ncs[3] write enable read enable memory enable nwr1 write enable read enable memory enable d[7:0] d[7:0] d[15:8] d[15:8] a[24:2] a[23:1] a[23:1] a[0] a[0] signal name 16-bit bus 8-bit bus device type 1 x 16-bit 2 x 8-bit 1 x 8-bit byte access type (bat) byte select byte write nbs0_a0 nbs0 a0 nwe_nwr0 nwe nwr0 nwe nbs1_nwr1 nbs1 nwr1 nbs2_nwr2_a1 a1 a1 a1
183 32072d?04/2011 at32uc3a3/a4 access type. nwr0 to nwr1 have the same ti mings and protocol as nwe. in the same way, ncs represents one of the ncs[0..5] chip select lines. 15.6.4.1 read waveforms the read cycle is shown on figure 15-7 on page 183 . the read cycle starts with the address setting on the memory address bus, i.e.: {a[23:2], a1, a0} for 8-bit devices {a[23:2], a1} for 16-bit devices figure 15-7. standard read cycle ?nrd waveform the nrd signal is characterized by a se tup timing, a pulse width, and a hold timing. 1. nrdsetup: the nrd setup time is defined as the setup of address before the nrd falling edge. 2. nrdpulse: the nrd pulse length is the time between nrd falling edge and nrd ris- ing edge. 3. nrdhold: the nrd hold time is defined as the hold time of address after the nrd ris- ing edge. ?ncs waveform similarly, the ncs signal can be divided into a setup time, pulse length and hold time. a[ad_msb:2] clk_smc nbs0, nbs1, a0, a1 nrd ncs d[15:0] ncsrdsetup nrdsetup nrdpulse ncsrdpulse nrdcycle nrdhold ncsrdhold
184 32072d?04/2011 at32uc3a3/a4 1. ncsrdsetup: the ncs setup time is defined as the setup time of address before the ncs falling edge. 2. ncsrdpulse: the ncs pulse length is t he time between ncs falling edge and ncs rising edge. 3. ncsrdhold: the ncs hold time is defined as the hold time of address after the ncs rising edge. ?read cycle the nrdcycle time is defined as the total duration of the read cycle, i.e., from the time where address is set on the address bus to the point where address may change. the total read cycle time is equal to: similarly, all nrd and ncs timings are defined separately for each chip select as an integer number of clk_smc cycles. to ensure that the nrd and ncs timings ar e coherent, the user must define the total read cycle instead of the hold timing. nrdcycle implicitly defines the nrd hold time and ncs hold time as: and, ?null delay setup and hold if null setup and hold parame ters are programmed for nrd and/or ncs, nrd and ncs remain active continuously in case of consecutive read cycles in the same memory (see figure 15-8 on page 185 ). nrdcycle nrdsetup nrdpulse nrdhold ++ = nrdcycle ncsrdsetup ncsrdpulse ncsrdhold ++ = nrdhold nrdcycle nrdsetup ? nrdpulse ? = ncsrdhold nrdcycle ncsrdsetup ? ncsrdpulse ? =
185 32072d?04/2011 at32uc3a3/a4 figure 15-8. no setup, no hold on nrd, and ncs read signals ? null pulse programming null pulse is not permitted. pulse must be at least written to one. a null value leads to unpredictable behavior. 15.6.4.2 read mode as ncs and nrd waveforms are defined independently of one other, the smc needs to know when the read data is available on the data bus. the smc does not compare ncs and nrd tim- ings to know which signal rises first. the read mode bit in the mode register (mode.readmode) of the corresponding chip se lect indicates which signal of nrd and ncs controls the read operation. ?read is controlled by nrd (mode.readmode = 1) figure 15-9 on page 186 shows the waveforms of a read operation of a typical asynchronous ram. the read data is available t pacc after the falling edge of nrd, and turns to ?z? after the ris- ing edge of nrd. in this case, the mode.readmode bit must be written to one (read is controlled by nrd), to indicate th at data is availabl e with the rising edge of nrd. the smc sam- ples the read data internally on the rising ed ge of clk_smc that generates the rising edge of nrd, whatever the programmed waveform of ncs may be. clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nrd ncs d[15:0] nrdsetup nrdpulse ncsrdpulse nrdcycle nrdcycle ncsrdpulse ncsrdpulse nrdpulse nrdcycle
186 32072d?04/2011 at32uc3a3/a4 figure 15-9. readmode = 1: data is sampled by smc before the rising edge of nrd ?read is controlled by ncs (mode.readmode = 0) figure 15-10 on page 187 shows the typical read cycle of an lcd module. the read data is valid t pacc after the falling edge of the ncs signal and remains valid until the rising edge of ncs. data must be sampled when ncs is raised. in that case, the mode.readmode bit must be written to zero (read is controlled by ncs): the smc internally samples the data on the rising edge of cml_smc that generates the rising edge of ncs, whatever the programmed waveform of nrd may be. clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nrd ncs d[15:0] t pacc data sampling
187 32072d?04/2011 at32uc3a3/a4 figure 15-10. readmode = 0: data is sampled by smc before the rising edge of ncs 15.6.4.3 write waveforms the write protocol is similar to the read protocol. it is depicted in figure 15-11 on page 188 . the write cycle starts with the address setting on the memory address bus. ?nwe waveforms the nwe signal is characterized by a setu p timing, a pulse width and a hold timing. 1. nwesetup: the nwe setup time is defined as the setup of address and data before the nwe falling edge. 2. nwepulse: the nwe pulse length is the time between nwe falling edge and nwe rising edge. 3. nwehold: the nwe hold time is defined as the hold time of address and data after the nwe rising edge. the nwe waveforms apply to all byte-write lines in byte write access mode: nwr0 to nwr3. 15.6.4.4 ncs waveforms the ncs signal waveforms in write operation are not the same that those applied in read opera- tions, but are separately defined. 1. ncswrsetup: the ncs setup time is defined as the setup time of address before the ncs falling edge. 2. ncswrpulse: the ncs pulse length is th e time between ncs falling edge and ncs rising edge; 3. ncswrhold: the ncs hold time is defined as the hold time of address after the ncs rising edge. clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nrd ncs d[15:0] t pacc data sampling
188 32072d?04/2011 at32uc3a3/a4 figure 15-11. write cycle ?write cycle the write cycle time is defined as the total duration of the write cycle, that is, from the time where address is set on the address bus to the point where address may change. the total write cycle time is equal to: similarly, all nwe and ncs (write) timings are defined separately for each chip select as an integer num- ber of clk_smc cycles. to ensure that the nwe and ncs timings are coherent, the user must define the total write cycle instead of the hold timi ng. this implicitly defines the nwe hold time and ncs (write) hold times as: and, clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nwe ncs nwesetup nwepulse ncswrpulse ncswrsetup nwecycle nwehold ncswrhold nwecycle nwesetup nwepulse nwehold ++ = nwecycle ncswrsetup ncswrpulse ncswrhold ++ = nwehold nwecycle nwesetup ? nwepulse ? = ncswrhold nwecycle ncswrsetup ? ncswrpulse ? =
189 32072d?04/2011 at32uc3a3/a4 ?null delay setup and hold if null setup parameters are programmed for nwe and/or ncs, nwe and/or ncs remain active continuously in case of consecutive wr ite cycles in the same memory (see figure 15-12 on page 189 ). however, for devices that perform write operations on the rising edge of nwe or ncs, such as sram, either a setup or a hold must be programmed. figure 15-12. null setup and hold values of ncs and nwe in write cycle ?null pulse programming null pulse is not permitted. pulse must be at least written to one. a null value leads to unpredictable behavior. 15.6.4.5 write mode the write mode bit in the mode register (mode.writemode) of the corresponding chip select indicates which signal controls the write operation. ?write is controlled by nwe (mode.writemode = 1) figure 15-13 on page 190 shows the waveforms of a writ e operation with mode.writemode equal to one. the data is put on the bus during the pulse and hold steps of the nwe signal. the internal data buffers are turned out after the nwesetup time, and until the end of the write cycle, regardless of the programmed waveform on ncs. clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nwe, nwe0, nwe1 ncs nwesetup nwepulse ncswrpulse ncswrsetup nwecycle d[15:0] nwecycle nwepulse ncswrpulse nwecycle
190 32072d?04/2011 at32uc3a3/a4 figure 15-13. writemode = 1. the write operation is controlled by nwe ?write is controlled by ncs (mode.writemode = 0) figure 15-14 on page 190 shows the waveforms of a writ e operation with mode.writemode written to zero. the data is put on the bus during the pulse and hold steps of the ncs signal. the internal data buffers are turned out after the ncswrsetup time, and until the end of the write cycle, regardless of the programmed waveform on nwe. figure 15-14. writemode = 0. the write operation is controlled by ncs clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nwe, nwr0, nwr1 ncs d[15:0] clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nwe, nwr0, nwr1 ncs d[15:0]
191 32072d?04/2011 at32uc3a3/a4 15.6.4.6 coding timing parameters all timing parameters are defined for one chip select and are grouped together in one register according to their type. the setup register (setup) groups the definition of all setup parameters: ? nrdsetup, ncsrdsetup, nwesetup, and ncswrsetup. the pulse register (pulse) groups the definition of all pulse parameters: ? nrdpulse, ncsrdpulse, nwepulse, and ncswrpulse. the cycle register (cycle) groups the definition of all cycle parameters: ? nrdcycle, nwecycle. table 15-4 on page 191 shows how the timing parameters are coded and their permitted range. 15.6.4.7 usage restriction the smc does not check the validity of the user-programmed parameters. if the sum of setup and pulse parameters is larger than the corresponding cycle parameter, this leads to unpre- dictable behavior of the smc. for read operations: null but positive setup and hold of address and nrd and/or ncs can not be guaranteed at the memory interface because of the propagation dela y of theses signals through external logic and pads. if positive setup and hold values must be verified, then it is strictly recommended to pro- gram non-null values so as to cover possible skews between address, ncs and nrd signals. for write operations: if a null hold value is programmed on nwe, the smc can guarantee a positive hold of address, byte select lines, and ncs signal after the rising edge of nwe. this is true if the mode.write- mode bit is written to one. see section 15.6.5.2 . for read and write operations: a null value for pulse parameters is forbidden and may lead to unpredictable behavior. in read and write cycles, the setup and hold time parameters are defined in reference to the address bus. for external devices that require setup and hold time between ncs and nrd sig- nals (read), or between ncs and nwe signals (write), these setup and hold times must be converted into setup and hold times in reference to the address bus. table 15-4. coding and range of timing parameters coded value number of bits effective value permitted range coded value effective value setup [5:0] 6 128 x setup[5] + setup[4:0] 0 value 31 32 value 63 0 value 31 128 value 128+31 pulse [6:0] 7 256 x pulse[6] + pulse[5:0] 0 value 63 64 value 127 0 value 63 256 value 256+63 cycle [8:0] 9 256 x cycle[8:7] + cycle[6:0] 0 value 127 128 value 255 256 value 383 384 value 511 0 value 127 256 value 256+127 512 value 512+127 768 value 768+127
192 32072d?04/2011 at32uc3a3/a4 15.6.5 automatic wait states under certain circumstances, the smc automatica lly inserts idle cycles between accesses to avoid bus contention or operation conflict. 15.6.5.1 chip sele ct wait states the smc always inserts an idle cycle between two transfers on separate ch ip selects. this idle cycle ensures that there is no bus contention bet ween the deactivation of one device and the activation of the next one. during chip select wait state, all control li nes are turned inactive: nbs0 to nbs3, nwr0 to nwr3, ncs[0..5], nrd lines are all set to high level. figure 15-15 on page 192 illustrates a chip select wait stat e between access on chip select 0 (ncs0) and chip select 2 (ncs2). figure 15-15. chip select wait state between a read access on ncs0 and a write access on ncs2 15.6.5.2 early read wait state in some cases, the smc inserts a wait state cycle between a write access and a read access to allow time for the write cycle to end before the subsequent read cycle begins. this wait state is not generated in addition to a chip select wait state. the early read cycle thus only occurs between a write and read access to the same memory device (same chip select). clk_smc _msb:2] , nbs1, , a1 nrd nwe ncs0 ncs2 d[15:0] nrdcycle read to write wait state chip select wait state nwecycle
193 32072d?04/2011 at32uc3a3/a4 an early read wait state is automatically inserted if at least one of the following conditions is valid: ? if the write controlling signal has no hold time and the read controlling signal has no setup time ( figure 15-16 on page 193 ). ? in ncs write controlled mode (mode.writemode = 0), if there is no hold timing on the ncs signal and the ncsrdsetup parameter is set to zero, regardless of the read mode ( figure 15-17 on page 194 ). the write operation must end with a ncs rising edge. without an early read wait state, the write operation could not complete properly. ? in nwe controlled mode (mode.writemode = 1) and if there is no hold timing (nwehold = 0), the feedback of the write control signal is used to control address, data, chip select, and byte select lines. if the extern al write control signal is not inactivated as expected due to load capacitances, an early read wait state is inserted and address, data and control signals are maintained one more cycle. see figure 15-18 on page 195 . figure 15-16. early read wait state: write with no hold followed by read with no setup. clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nwe nrd d[15:0] no hold no setup read cycle early read wait state write cycle
194 32072d?04/2011 at32uc3a3/a4 figure 15-17. early read wait state: ncs controlled write with no hold followed by a read with no setup. clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nwe nrd d[15:0] no hold no setup read cycle (readmode=0 or readmode=1) early read wait state write cycle (writemode=0)
195 32072d?04/2011 at32uc3a3/a4 figure 15-18. early read wait state: nwe-controlled write with no hold followed by a read with one set-up cycle. 15.6.5.3 reload user configuration wait state the user may change any of the configuration parameters by writing the smc user interface. when detecting that a new user configuration has been written in the user interface, the smc inserts a wait state before starting the next access. the so called ?reload user configuration wait state? is used by the smc to load the new set of parameters to apply to next accesses. the reload configuration wa it state is not applied in addition to the chip select wait state. if accesses before and after reprogramming the user interface are made to different devices (dif- ferent chip selects), then one single chip select wait state is applied. on the other hand, if accesses before and after writing the user interface are made to the same device, a reload configuration wait state is inserted, even if the change does not concern the cur- rent chip select. ?user procedure to insert a reload configuration wait state, the smc detects a write access to any mode register of the user interface. if the user only modifies timing registers (setup, pulse, cycle regis- ters) in the user interface, he must validate th e modification by writing the mode register, even if no change was made on the mode parameters. clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 internal write controlling signal external write controlling signal(nwe) nrd d[15:0] no hold read setup=1 write cycle (writemode = 1) early read wait state read cycle (readmode=0 or readmode=1)
196 32072d?04/2011 at32uc3a3/a4 ?slow clock mode transition a reload configuration wait state is also inserted when the slow clock mode is entered or exited, after the end of the current transfer (see section 15.6.8 ). 15.6.5.4 read to write wait state due to an internal mechanism, a wait cycle is always inserted between consecutive read and write smc accesses. this wait cycle is referred to as a read to write wait stat e in this document. this wait cycle is applied in add ition to chip select and reload user configuration wait states when they are to be inserted. see figure 15-15 on page 192 . 15.6.6 data float wait states some memory devices are slow to release the exte rnal bus. for such devices, it is necessary to add wait states (data float wait states) after a read access: ? before starting a read access to a different external memory. ? before starting a write access to the same device or to a different external one. the data float output time (t df ) for each external memory device is programmed in the data float time field of the mode register (mod e.tdfcycles) for the corresponding chip select. the value of mode.tdfcycles indicates the number of data float wait cycles (between 0 and 15) before the external device releases the bus, and represents the time allowed for the data output to go to high impedance after the memory is disabled. data float wait states do not delay internal memory accesses. hence, a single access to an external memory with long t df will not slow down the executio n of a program from internal memory. the data float wait states management depends on the mode.readmode bit and the tdf optimization bit of the mode register (mode. tdfmode) for the corresponding chip select. 15.6.6.1 read mode writing a one to the mode.readmo de bit indicates to the smc that the nrd signal is respon- sible for turning off the tri-state buffers of the external memory device. the data float period then begins after the rising edge of the nrd signal and lasts mode.tdfcycles cycles of the clk_smc clock. when the read operation is controlled by the ncs signal (mode.readmode = 0), the mode.tdfcycles field gives the number of clk_smc cycles during which the data bus remains busy after the rising edge of ncs. figure 15-19 on page 197 illustrates the data float period in nrd-controlled mode (mode.readmode =1), assuming a data float period of two cycles (mode.tdfcycles = 2). figure 15-20 on page 197 shows the read operation when controlled by ncs (mode.read- mode = 0) and the mode.tdfcycles field equals to three.
197 32072d?04/2011 at32uc3a3/a4 figure 15-19. tdf period in nrd controlled read access (tdfcycles = 2) figure 15-20. tdf period in ncs controlled r ead operation (tdfcycles = 3) clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nrd ncs d[15:0] t pacc nrd controlled read operation tdf = 2 clock cycles clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nrd ncs d[15:0] t pacc ncs controlled read operation tdf = 3 clock cycles
198 32072d?04/2011 at32uc3a3/a4 15.6.6.2 tdf optimization enabled (mode.tdfmode = 1) when the mode.tdfmode bit is written to one (tdf optimization is enabled), the smc takes advantage of the setup period of the next access to optimize the number of wait states cycle to insert. figure 15-21 on page 198 shows a read access controlled by nrd, followed by a write access controlled by nwe, on chip select 0. chip select 0 has been programmed with: nrdhold = 4; readmode = 1 (nrd controlled) nwesetup = 3; writemode = 1 (nwe controlled) tdfcycles = 6; tdfmode = 1 (optimization enabled). figure 15-21. tdf optimization: no tdf wait states are inserted if the tdf period is over when the next access begins 15.6.6.3 tdf optimization disabled (mode.tdfmode = 0) when optimization is disabled, data float wait states are inserted at the end of the read transfer, so that the data float period is ended when the second access begins. if the hold period of the read1 controlling signal ov erlaps the data float period, no additional data float wait states will be inserted. figure 15-22 on page 199 , figure 15-23 on page 199 and figure 15-24 on page 200 illustrate the cases: ? read access followed by a read access on another chip select. ? read access followed by a write access on another chip select. clk_smc a[ad_msb:2] nrd nwe ncs0 d[15:0] read access on ncs0 (nrd controlled) read to write wait state write access on ncs0 (nwe controlled) tdfcycles = 6 nwesetup = 3 nrdhold = 4
199 32072d?04/2011 at32uc3a3/a4 ? read access followed by a write access on the same chip select. with no tdf optimization. figure 15-22. tdf optimization disabled (mode.tdfmode = 0). tdf wait states between two read accesses on dif- ferent chip selects. figure 15-23. tdf optimization disabled (mode.tdfmode= 0). tdf wait states between a read and a write access on different chip selects. clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 read1 controlling signal(nrd) read2 controlling signal(nrd) d[15:0] read1 hold = 1 read1 cycle tdfcycles = 6 chip select wait state 5 tdf wait states tdfcycles = 6 read2 setup = 1 read 2 cycle tdfmode=0 (optimization disabled) clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 read1 controlling signal(nrd) write2 controlling signal(nwe) d[15:0] read1 cycle tdfcycles = 4 chip select wait state read1 hold = 1 tdfcycles = 4 read to write wait state 2 tdf wait states write2 setup = 1 write 2 cycle tdfmode=0 (optimization disabled)
200 32072d?04/2011 at32uc3a3/a4 figure 15-24. tdf optimization disabled (mode.tdfmode = 0). tdf wa it states between read and write accesses on the same chip select. 15.6.7 external wait any access can be extended by an external device using the nw ait input signal of the smc. the external wait mode field of the mode register (mode.exnwmode) on the corresponding chip select must be written to either two (frozen mode) or three (ready mode). when the mode.exnwmode field is written to zero (disabled), the nwait signal is simply ignored on the corresponding chip select. the nwait signal delays the read or write operation in regards to the read or write controlling signal, depending on the read and wr ite modes of the corresponding chip select. 15.6.7.1 restriction when one of the mode.exnwmode is enabled, it is mandatory to program at least one hold cycle for the read/write controlling signal. for that reason, the nwait signal cannot be used in page mode ( section 15.6.9 ), or in slow clock mode ( section 15.6.8 ). the nwait signal is assumed to be a response of the external device to the read/write request of the smc. then nwait is examined by the smc only in the pulse state of the read or write controlling signal. the assertion of the nwait signal outside th e expected period has no impact on smc behavior. 15.6.7.2 frozen mode when the external device asserts the nwait signal (active low), and after internal synchroniza- tion of this signal, the smc state is frozen, i.e., smc internal counters are frozen, and all control signals remain unchanged. when the synchroniz ed nwait signal is deasserted, the smc com- pletes the access, resuming the access from the point where it was stopped. see figure 15-25 on page 201 . this mode must be selected when the external device uses the nwait signal to delay the access and to freeze the smc. clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 read1 controlling signal(nrd) write2 controlling signal(nwe) d[15:0] read1 hold = 1 tdfcycles = 5 read1 cycle tdfcycles = 5 read to write wait state 4 tdf wait states write2 setup = 1 write 2 cycle tdfmode=0 (optimization disabled)
201 32072d?04/2011 at32uc3a3/a4 the assertion of the nwait sign al outside the expected period is ignored as illustrated in figure 15-26 on page 202 . figure 15-25. write access with nwait assertion in frozen mode (mode.exnwmode = 2). clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nwe ncs d[15:0] 654 4 3 3 2 21 1 2 1 22 1 0 0 frozen state nwait internally synchronized nwait signal write cycle exnwmode = 2 (frozen) writemode = 1 (nwe controlled) nwepulse = 5 ncswrpulse = 7
202 32072d?04/2011 at32uc3a3/a4 figure 15-26. read access with nwait assertion in frozen mode (mode.exnwmode = 2). clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 ncs nrd nwait internally synchronized nwait signal exnwmode = 2 (frozen) readmode = 0 (ncs controlled) nrdpulse = 2, nrdhold = 6 ncsrdpulse = 5, ncsrdhold = 3 read cycle assertion is ignored 43 2 10 22 1 0 5 55 4 3 2 21 10 0 frozen state
203 32072d?04/2011 at32uc3a3/a4 15.6.7.3 ready mode in ready mode (mode.exnwmode = 3), the smc behaves differently. normally, the smc begins the access by down counting the setup and pulse counters of the read/write controlling signal. in the last cycle of the pulse phase, the resynchronized nwait signal is examined. if asserted, the smc suspends the access as shown in figure 15-27 on page 203 and figure 15-28 on page 204 . after deassertion, the access is completed: the hold step of the access is performed. this mode must be selected when the external de vice uses deassertion of the nwait signal to indicate its ability to complete the read or write operation. if the nwait signal is deasserted before the end of the pulse, or asserted after the end of the pulse of the controlling read/write signal, it has no impact on the access length as shown in fig- ure 15-28 on page 204 . figure 15-27. nwait assertion in write access: ready mode (mode.exnwmode = 3). clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nwe ncs d[15:0] 654 4 3 3 2 21 0 1 0 11 0 frozen state nwait internally synchronized nwait signal write cycle exnwmode = 3 (ready mode) writemode = 1 (nwe_controlled) nwepulse = 5 ncswrpulse = 7 0
204 32072d?04/2011 at32uc3a3/a4 figure 15-28. nwait assertion in read access : ready mode (exnwmode = 3). clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 ncs nrd 6 6 5 5 4 4 3 2 3 1 21 0 nwait internally synchronized nwait signal read cycle exnwmode = 3 (ready mode) readmode = 0 (ncs_controlled) nrdpulse = 7 ncsrdpulse = 7 1 0 0 assertion is ignored assertion is ignored wait state
205 32072d?04/2011 at32uc3a3/a4 15.6.7.4 nwait latency and read/write timings there may be a latency between the assertion of the read/w rite controlling signal and the asser- tion of the nwait signal by the device. t he programmed pulse length of the read/write controlling signal must be at least equal to this latency plus the two cy cles of resynchronization plus one cycle. otherwise, the smc may enter the hold state of the access without detecting the nwait signal assertion. this is true in frozen mode as well as in ready mode. th is is illustrated on figure 15-29 on page 205 . when the mode.exnwmode field is enabled (ready or frozen), the user must program a pulse length of the read and write controlling si gnal of at least: figure 15-29. nwait latency minimal pulse length nwait latency 2 synchronization cycles 1 cycle ++ = wait state 0 1 2 3 4 clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 nrd nwait nternally synchronized nwait signal minimal pulse length 0 0 nwait latency 2 cycle resynchronization read cycle exnwmode = 2 or 3 readmode = 1 (nrd controlled) nrdpulse = 5
206 32072d?04/2011 at32uc3a3/a4 15.6.8 slow clock mode the smc is able to automatically apply a set of ?slow clock mode? read/write waveforms when an internal signal driven by the smc?s po wer management controller is asserted because clk_smc has been turned to a very slow clock rate (typically 32 khz clock rate). in this mode, the user-programmed waveforms are ignored and the slow clock mode waveforms are applied. this mode is provided so as to avoid reprogram ming the user interface with appropriate wave- forms at very slow clock rate. when activated, the slow mode is active on all chip selects. 15.6.8.1 slow clock mode waveforms figure 15-30 on page 206 illustrates the read and write operations in slow clock mode. they are valid on all chip selects. table 15-5 on page 206 indicates the value of read and write parame- ters in slow clock mode. figure 15-30. read and write cycles in slow clock mode clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 ncs nwe nwecycles = 3 slow clock mode write 1 1 1 clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 ncs nrd slow clock mode read nrdcycles = 2 1 1 table 15-5. read and write timing parameters in slow clock mode read parameters duration (cycles) write parameters duration (cycles) nrdsetup 1 nwesetup 1 nrdpulse 1 nwepulse 1 ncsrdsetup 0 ncswrsetup 0 ncsrdpulse 2 ncswrpulse 3 nrdcycle 2 nwecycle 3
207 32072d?04/2011 at32uc3a3/a4 15.6.8.2 switching from (to) slow clock mode to (from) normal mode when switching from slow clock mode to the nor mal mode, the current slow clock mode transfer is completed at high clock rate, with the set of slow clock mode parameters. see figure 15-31 on page 207 . the external device may not be fast enough to support such timings. figure 15-32 on page 208 illustrates the recommended procedur e to properly switch from one mode to the other. figure 15-31. clock rate transition occurs while the smc is performing a write operation clk_smc a[ad_msb:2] nbs0, nbs1, a0, a1 ncs nwe slow clock mode internal signal from pm this write cycle finishes with the slow clock mode set of parameters after the clock rate transition nwecycle = 3 slow clock mode write slow clock mode write 11 1 1 1 1 2 3 2 nwecycle = 7 normal mode write slow clock mode transition is detected: reload configuration wait state
208 32072d?04/2011 at32uc3a3/a4 figure 15-32. recommended procedure to switch from slow clock mo de to normal mode or from normal mode to slow clock mode 15.6.9 asynchronous page mode the smc supports asynchronous burst reads in page mode, providing that the page mode enabled bit is written to one in the mode register (mode.pmen). the page size must be con- figured in the page size field in the mode register (mode.ps) to 4, 8, 16, or 32 bytes. the page defines a set of consecutive bytes into memory. a 4-byte page (resp. 8-, 16-, 32-byte page) is always aligned to 4-byte boundaries (resp. 8-, 16-, 32-byte boundaries) of memory. the msb of data address defines the address of the page in memory, the lsb of address define the address of the data in the page as detailed in table 15-6 on page 208 . with page mode memory devices, the first access to one page (t pa ) takes longer than the subse- quent accesses to the page (t sa ) as shown in figure 15-33 on page 209 . when in page mode, the smc enables the user to define different r ead timings for the first access within one page, and next accesses within the page. notes: 1. a denotes the address bus of the memory device 2. for 16-bit devices, the bit 0 of address is ignored. 15.6.9.1 protocol and timings in page mode figure 15-33 on page 209 shows the nrd and ncs timings in page mode access. clk_smc slow clock mode internal signal from pm a[ad_msb:2] nbs0, nbs1, a0, a1 nwe ncs 11 slow clock mode write 23 2 idle state reload configuration wait state normal mode write 1 table 15-6. page address and data address within a page page size page address (1) data address in the page (2) 4 bytes a[23:2] a[1:0] 8 bytes a[23:3] a[2:0] 16 bytes a[23:4] a[3:0] 32 bytes a[23:5] a[4:0]
209 32072d?04/2011 at32uc3a3/a4 figure 15-33. page mode read protocol (address msb and lsb are defined in table 15-6 on page 208 ) the nrd and ncs signals are held low during all read transfers, whatever the programmed val- ues of the setup and hold timings in the us er interface may be. moreover, the nrd and ncs timings are identical. the pulse length of the first access to the page is defined with the pulse.ncsrdpulse field value. the pulse length of subsequent accesses within the page are defined using the pulse.nrdpulse field value. in page mode, the programming of the read timings is described in table 15-7 on page 209 : the smc does not check the coherency of timi ngs. it will always apply the ncsrdpulse tim- ings as page access timing (t pa ) and the nrdpulse for accesses to the page (t sa ), even if the programmed value for t pa is shorter than the programmed value for t sa . 15.6.9.2 byte access type in page mode the byte access type configuration remains active in page mode. for 16-bit or 32-bit page mode devices that require byte select ion signals, configure the mode.bat bit to zero (byte select access type). clk_smc a[msb] a[lsb] ncs nrd d[15:0] t pa ncsrdpulse t sa nrdpulse nrdpulse t sa table 15-7. programming of read timings in page mode parameter value definition readmode ?x? no impact ncsrdsetup ?x? no impact ncsrdpulse t pa access time of first access to the page nrdsetup ?x? no impact nrdpulse t sa access time of subsequent accesses in the page nrdcycle ?x? no impact
210 32072d?04/2011 at32uc3a3/a4 15.6.9.3 page mode restriction the page mode is not compatible with the use of the nwait signal. using the page mode and the nwait signal may lead to unpredictable behavior. 15.6.9.4 sequential and non-sequential accesses if the chip select and the msb of addresses as defined in table 15-6 on page 208 are identical, then the current access lies in the same page as the previous one, and no page break occurs. using this information, all data within the same page, sequential or not sequential, are accessed with a minimum access time (t sa ). figure 15-34 on page 210 illustrates access to an 8-bit mem- ory device in page mode, with 8-byte pages. access to d1 causes a page access with a long access time (t pa ). accesses to d3 and d7, though they are not sequential accesses, only require a short access time (t sa ). if the msb of addresses are different, the smc performs the access of a new page. in the same way, if the chip select is diffe rent from the previous access, a page break occurs. if two sequen- tial accesses are made to the page mode memory , but separated by an other internal or external peripheral access, a page break occurs on the second access because the chip select of the device was deasserted between both accesses. figure 15-34. access to non-sequential data within the same page clk_smc a[ad_msb:3] a[2], a1, a0 ncs nrd d[7:0] a1 page address a3 a7 d1 d3 d7 ncsrdpulse nrdpulse nrdpulse
211 32072d?04/2011 at32uc3a3/a4 15.7 user interface the smc is programmed using the registers listed in table 15-8 on page 211 . for each chip select, a set of four registers is used to program the parameters of the external device connected on it. in table 15-8 on page 211 , ?cs_number? denotes the chip select number. sixteen bytes (0x10) are required per chip select. the user must complete writing the configuration by writing anyone of the mode registers. table 15-8. smc register memory map offset register register name access reset 0x00 + cs_number*0x10 setup re gister setup read/write 0x01010101 0x04 + cs_number*0x10 pulse register pulse read/write 0x01010101 0x08 + cs_number*0x10 cycle register cycle read/write 0x00030003 0x0c + cs_number*0x10 mode register mode read/write 0x10002103
212 32072d?04/2011 at32uc3a3/a4 15.7.1 setup register register name: setup access type: read/write offset: 0x00 + cs_number*0x10 reset value: 0x01010101 ? ncsrdsetup: ncs setup length in read access in read access, the ncs signal setup length is defined as: ? nrdsetup: nrd setup length the nrd signal setup length is defined in clock cycles as: ? ncswrsetup: ncs setup length in write access in write access, the ncs signal setup length is defined as: ? nwesetup: nwe setup length the nwe signal setup length is defined as: 31 30 29 28 27 26 25 24 ?? ncsrdsetup 23 22 21 20 19 18 17 16 ?? nrdsetup 15 14 13 12 11 10 9 8 ?? ncswrsetup 76543210 ?? nwesetup ncs setup length in read access 128 ncsrdsetup 5 [] ncsrdsetup 4:0 [] + () clock cycles = nrd setup length 128 nrdsetup 5 [] nrdsetup 4:0 [] + () clock cycles = ncs setup length in write access 128 ncswrsetup 5 [] ncswrsetup 4:0 [] + () clock cycles = nwe setup length 128 nwesetup 5 [] nwesetup 4:0 [] + () clock cycles =
213 32072d?04/2011 at32uc3a3/a4 15.7.2 pulse register register name: pulse access type: read/write offset: 0x04 + cs_number*0x10 reset value: 0x01010101 ? ncsrdpulse: ncs pulse length in read access in standard read access, the ncs signal pulse length is defined as: the ncs pulse lengt h must be at least one clock cycle. in page mode read access, the ncsrdpulse field defines the duration of the first access to one page. ? nrdpulse: nrd pulse length in standard read access, the nrd signal puls e length is defined in clock cycles as: the nrd pulse length must be at least one clock cycle. in page mode read access, the nrdpulse field defines t he duration of the subsequent accesses in the page. ? ncswrpulse: ncs pulse length in write access in write access, the ncs signal pulse length is defined as: the ncs pulse lengt h must be at least one clock cycle. ? nwepulse: nw e pulse length the nwe signal pulse length is defined as: the nwe pulse leng th must be at least one clock cycle. 31 30 29 28 27 26 25 24 ? ncsrdpulse 23 22 21 20 19 18 17 16 ? nrdpulse 15 14 13 12 11 10 9 8 ? ncswrpulse 76543210 ? nwepulse ncs pulse length in read access 256 ncsrdpulse 6 [] ncsrdpulse 5:0 [] + () clock cycles = nrd pulse length 256 nrdpulse 6 [] nrdpulse 5:0 [] + () clock cycles = ncs pulse length in write access 256 ncswrpulse 6 [] ncswrpulse 5:0 [] + () clock cycles = nwe pulse length 256 nwepulse 6 [] nwepulse 5:0 [] + () clock cycles =
214 32072d?04/2011 at32uc3a3/a4 15.7.3 cycle register register name: cycle access type: read/write offset: 0x08 + cs_number*0x10 reset value: 0x00030003 ? nrdcycle[8:0]: total read cycle length the total read cycle leng th is the total duration in clock cycles of the read cycle. it is equal to the sum of the setup, pulse and hold steps of the nrd and ncs signals. it is defined as: ? nwecycle[8:0]: total write cycle length the total write cycle length is the total duration in clock cycles of the write cycle. it is equal to the sum of the setup, pul se and hold steps of the nwe and ncs signals. it is defined as: 31 30 29 28 27 26 25 24 ??????? nrdcycle[8] 23 22 21 20 19 18 17 16 nrdcycle[7:0] 15 14 13 12 11 10 9 8 ??????? nwecycle[8] 76543210 nwecycle[7:0] read cycle length 256 nrdcycle 8:7 [] nrdcycle 6:0 [] + () clock cycles = write cycle length 256 nwecycle 8:7 [] nwecycle 6:0 [] + () clock cycles =
215 32072d?04/2011 at32uc3a3/a4 15.7.4 mode register register name: mode access type: read/write offset: 0x0c + cs_number*0x10 reset value: 0x10002103 ? ps: page size if page mode is enabled, this field indicates the size of the page in bytes. ? pmen: page mode enabled 1: asynchronous burst read in page mode is applied on the corresponding chip select. 0: standard read is applied. ? tdfmode: tdf optimization 1: tdf optimization is enabled. the number of tdf wait states is optimized using the setup period of the next read/write access. 0: tdf optimization is disabled.the number of tdf wait states is inserted before the next access begins. ? tdfcycles: data float time this field gives the integer numb er of clock cycles required by the external de vice to release the dat a after the rising edge o f the read controlling signal. the smc always provide one full cycle of bus turnaround after the tdfcycles period. the external bus cannot be used by another chip select during tdfcycle s plus one cycles. from 0 up to 15 tdfcycles can be set. 31 30 29 28 27 26 25 24 ?? ps ??? pmen 23 22 21 20 19 18 17 16 ??? tdfmode tdfcycles 15 14 13 12 11 10 9 8 ?? dbw ??? bat 76543210 ?? exnwmode ??writemode readmode ps page size 0 4-byte page 1 8-byte page 2 16-byte page 3 32-byte page
216 32072d?04/2011 at32uc3a3/a4 ? dbw: data bus width ? bat: byte access type this field is used only if dbw defines a 16-bit data bus. ? exnwmode: external wait mode the nwait signal is used to extend the current read or write signal. it is only taken into account during the pulse phase of th e read and write contro lling signal. when the use of nwai t is enabled, at least one cycle ho ld duration must be programmed for the read and write controlling signal. ? writemode: write mode 1: the write operation is controlled by the nwe signal. if td f optimization is enabled (tdfmode =1), tdf wait states will be inserted after the setup of nwe. 0: the write operation is controlled by the ncs signal. if tdf opt imization is enabled (tdfmode =1), tdf wait states will be inserted after the setup of ncs. dbw data bus width 08-bit bus 116-bit bus 2 reserved 3 reserved bat byte access type 0 byte select access type: write operation is controlled using ncs, nwe, nbs0, nbs1 read operation is controlled using ncs, nrd, nbs0, nbs1 1 byte write access type: write operation is controlled using ncs, nwr0, nwr1 read operation is controlled using ncs and nrd exnwmode external nwait mode 0 disabled: the nwait input signal is ignored on the corresponding chip select. 1 reserved 2 frozen mode: if asserted, the nwait signal freezes the current read or write cycle. after deassertion, the read or write cycle is resumed from the poi nt where it was stopped. 3 ready mode: the nwait signal indicates the availability of the external device at the end of the pu lse of the controlling read or write signal, to complete the access. if high, the ac cess normally completes. if low, the access is extended until nwait returns high.
217 32072d?04/2011 at32uc3a3/a4 ? readmode: read mode readmode read access mode 0 the read operation is controlled by the ncs signal. if tdf are programmed, the external bus is marked busy after the rising edge of ncs. if tdf optimization is enabled (tdfmode = 1), tdf wa it states are inserted after the setup of ncs. 1 the read operation is controlled by the nrd signal. if tdf cycles are programmed, the external bus is marked busy after the rising edge of nrd. if tdf optimization is enabled (tdfmode =1), tdf wa it states are inserted after the setup of nrd.
218 32072d?04/2011 at32uc3a3/a4 16. sdram controller (sdramc) rev: 2.2.0.4 16.1 features ? 128-mbytes address space ? numerous configurations supported ? 2k, 4k, 8k row address memory parts ? sdram with two or four internal banks ? sdram with 16-bit data path ? programming facilities ? word, halfword, byte access ? automatic page break when memory boundary has been reached ? multibank ping-pong access ? timing parameters specified by software ? automatic refresh operation, refresh rate is programmable ? automatic update of ds, tcr and pa sr parameters (mobile sdram devices) ? energy-saving capabilities ? self-refresh, power-down, and deep power-down modes supported ? supports mobile sdram devices ? error detection ? refresh error interrupt ? sdram power-up initialization by software ? cas latency of one, two, and three supported ? auto precharge command not used 16.2 overview the sdram controller (sdramc) extends the memory capabilities of a chip by providing the interface to an external 16-bit sdram device. the page size supports ranges from 2048 to 8192 and the number of columns from 256 to 2048. it supports byte (8-bit) and halfword (16-bit) accesses. the sdramc supports a read or write burst length of one location. it keeps track of the active row in each bank, thus maximizing sdram perfo rmance, e.g., the application may be placed in one bank and data in the other banks. so as to optimize performance, it is advisable to avoid accessing different rows in the same bank. the sdramc supports a cas latency of one, two, or three and optimizes the read access depending on the frequency. the different modes available (self refresh, power-down, and deep power-down modes) mini- mize power consumption on the sdram device.
219 32072d?04/2011 at32uc3a3/a4 16.3 block diagram figure 16-1. sdram controller block diagram 16.4 i/o lines description memory controller power manager clk_sdramc sdramc chip select sdramc interrupt sdramc user interface peripheral bus i/o controller sdcs sdck sdcke ba[1:0] ras cas sdwe dqm[0] sdramc_a[9:0] d[15:0] ebi mux logic data[15:0] sdck sdcke ncs[1] ras cas addr[17:16] sdwe addr[0] dqm[1] nwe1 addr[11:2] sdramc_a[10] sda10 sdramc_a[12:11] addr[13:14] table 16-1. i/o lines description name description type active level sdck sdram clock output sdcke sdram clock enable output high sdcs sdram chip select output low ba[1:0] bank sele ct signals output ras row signal output low cas column signal output low sdwe sdram write enable output low
220 32072d?04/2011 at32uc3a3/a4 16.5 application example 16.5.1 hardware interface figure 16-2 on page 220 shows an example of sdram devi ce connection using a 16-bit data bus width. it is important to note that this example is given for a direct connection of the devices to the sdramc, without external bus interface or i/o controller multiplexing. figure 16-2. sdram controller connections to sdra m devices: 16-bit data bus width 16.5.2 software interface the sdram address space is organized into banks, rows, and columns. the sdramc allows mapping different memory types according to the values set in the sdramc configuration reg- ister (cr). the sdramc?s function is to ma ke the sdram device access protocol transparent to the user. table 16-2 on page 221 to table 16-4 on page 221 illustrate the sdram device memory map- ping seen by the user in correlation with the device structure. various configurations are illustrated. dqm[1:0] data mask enable signals output high sdramc_a[12:0] address bus output d[15:0] data bus input/output table 16-1. i/o lines description name description type active level 2mx8 sdram d0-d7 cs dqm clk cke we ras cas a0-a9 a11 ba0 a10 ba1 sdramc_a10 ba0 ba1 2mx8 sdram d0-d7 cs dqm clk cke we ras cas a0-a9 a11 ba0 a10 ba1 sdramc_a10 ba0 ba1 sdcs ba1 ba0 sdramc_a[0-12] sdram controller dqm[0-1] sdwe sdcke sdck cas ras d0-d31 dqm0 d0-d7 d8-d15 dqm1
221 32072d?04/2011 at32uc3a3/a4 16.5.2.1 16-bit memory data bus width notes: 1. m0 is the byte address inside a 16-bit halfword. 16.6 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 16.6.1 i/o lines the sdramc module signals pass through the external bus interface (ebi) module where they are multiplexed. the user must first configure the i/o controller to assign the ebi pins corre- sponding to sdramc signals to their peripheral function. if i/o lines of the ebi corresponding to sdramc signals are not used by the application, they can be used for other purposes by the i/o controller. 16.6.2 power management the sdramc must be properly stopped before entering in reset mode, i.e., the user must issue a deep power mode command in the mode (md) register and wait for the command to be completed. table 16-2. sdram configuration mapping: 2k rows, 256/512/1024/2048 columns cpu address line 272625242322212019181716151413121110987654321 0 ba[1:0] row[10:0] column[7:0] m0 ba[1:0] row[10:0] column[8:0] m0 ba[1:0] row[10:0] column[9:0] m0 ba[1:0] row[10:0] column[10:0] m0 table 16-3. sdram configuration mapping: 4k rows, 256/512/1024/2048 columns cpu address line 272625242322212019181716151413121110987654321 0 ba[1:0] row[11:0] column[7:0] m0 ba[1:0] row[11:0] column[8:0] m0 ba[1:0] row[11:0] column[9:0] m0 ba[1:0] row[11:0] column[10:0] m0 table 16-4. sdram configuration mapping: 8k rows, 256/512/1024/2048 columns cpu address line 272625242322212019181716151413121110987654321 0 ba[1:0] row[12:0] column[7:0] m0 ba[1:0] row[12:0] column[8:0] m0 ba[1:0] row[12:0] column[9:0] m0 ba[1:0] row[12:0] column[10:0] m0
222 32072d?04/2011 at32uc3a3/a4 16.6.3 clocks the clock for the sdramc bus interface (clk _sdramc) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to disable the sdramc before disabling the clock, to avoid freezing the sdramc in an undefined state. 16.6.4 interrupts the sdramc interrupt request line is connected to the interrupt controller. using the sdramc interrupt requires the interrupt controller to be programmed first. 16.7 functional description 16.7.1 sdram device initialization the initialization sequence is generated by softw are. the sdram devices are initialized by the following sequence: 1. sdram features must be defined in the cr register by writing the following fields with the desired value: asynchronous timings (txsr, tras, trcd, trp, trc, and twr), number of columns (nc), numb er of rows (nr), number of banks (nb), cas latency (cas), and the data bus width (dbw). 2. for mobile sdram devices, temperature compensated self refresh (tcsr), drive strength (ds) and partial array self refresh (pasr) fields must be defined in the low power register (lpr). 3. the memory device type field must be defined in the memory device register (mdr.md). 4. a no operation (nop) command must be i ssued to the sdram devices to start the sdram clock. the user must write the value one to the command mode field in the sdramc mode register (mr.mode) and perform a write access to any sdram address. 5. a minimum pause of 200s is provided to precede any signal toggle. 6. an all banks precharge command must be issued to the sdram devices. the user must write the value two to the mr.mode field and perform a write access to any sdram address. 7. eight auto refresh commands are provided. the user must write the value four to the mr.mode field and performs a write access to any sdram location eight times. 8. a load mode register command must be issued to program the parameters of the sdram devices in its mode register, in particular cas latency, burst type, and burst length. the user must write the value three to the mr.mode field and perform a write access to the sdram. the write address must be chosen so that ba[1:0] are set to zero. see section 16.8.1 for details about load mode register command. 9. for mobile sdram initialization, an extended load mode register command must be issued to program the sdram devices parame ters (tcsr, pasr, ds). the user must write the value five to the mr.mode field and perform a write access to the sdram. the write address must be chosen so that ba[1] or ba[0] are equal to one. see section 16.8.1 for details about extended load mode register command. 10. the user must go into normal mode, writing the value 0 to the mr.mode field and per- forming a write access at any location in the sdram. 11. write the refresh rate into the refresh timer count field in the refresh timer register (tr.count). the refresh rate is the delay between two successive refresh cycles. the sdram device requires a refresh every 15 .625s or 7.81s. with a 100mhz fre-
223 32072d?04/2011 at32uc3a3/a4 quency, the tr register must be written with the value 1562 (15.625 s x 100 mhz) or 781 (7.81 s x 100 mhz). after initialization, the sdram devices are fully functional. figure 16-3. sdram device initialization sequence 16.7.2 sdram controller write cycle the sdramc allows burst access or single acce ss. in both cases, the sdramc keeps track of the active row in each bank, thus maximizing performance. to initiate a burst access, the sdramc uses the transfer type signal provided by the master requesting the access. if the next access is a sequential write a ccess, writing to the sdram devi ce is carried out. if the next access is a write-sequential access, but the current access is to a boundary page, or if the next access is in another row, then the sdramc generates a precharge command, activates the new row and initiates a write co mmand. to comply with sdram timing parameters, additional clock cycles are inserted between precharge and active (t rp ) commands and between active and write (t rcd ) commands. for definition of these timing parameters, refer to the section 16.8.3 . this is described in figure 16-4 on page 224 . sdcke sdck sdramc_a[9:0] a10 sdramc_a[12:11] sdcs ras cas sdwe dqm inputs stable for 200 usec valid command precharge all banks 1st auto refresh 8th auto refresh lmr command t mrd t rc t rp
224 32072d?04/2011 at32uc3a3/a4 figure 16-4. write burst, 16-bit sdram access 16.7.3 sdram controller read cycle the sdramc allows burst access, incremental bur st of unspecified length or single access. in all cases, the sdramc keeps track of the acti ve row in each bank, thus maximizing perfor- mance of the sdram. if row and bank addresse s do not match the previous row/bank address, then the sdramc automatically generates a precharge command, activates the new row and starts the read command. to comply with the sdram timing para meters, additional clock cycles on sdck are inserted between precharge and active (t rp ) commands and between active and read (t rcd ) commands. these two parameters are set in the cr register of the sdramc. after a read command, additional wait states are generated to comply with the cas latency (one, two, or three clock delays specified in the cr register). for a single access or an incremented burst of unspecified length, the sdramc anticipates the next access. while the last valu e of the column is returned by the sdramc on the bus, the sdramc anticipates the read to the next column and thus anticipates the cas latency. this reduces the effect of the cas latency on the internal bus. for burst access of specified length (4, 8, 16 words), access is not anticipated. this case leads to the best performance. if the burst is broken (border, busy mode, etc.), the next access is han- dled as an incrementing burst of unspecified length. sdcs t rcd = 3 sdck sdramc_a[12:0] ras cas sdwe d[15:0] dna dnb dnc dnd dne dnf dng dnh dni dnj dnk dnl row n col b col c col d col e col f col g col h col i col k col l col j col a
225 32072d?04/2011 at32uc3a3/a4 figure 16-5. read burst, 16-bit sdram access 16.7.4 border management when the memory row boundary has been reached, an automatic page break is inserted. in this case, the sdramc generates a precharge command, activates the new row and initiates a read or write command. to comply with sdram timing parameters, an additional clock cycle is inserted between the precharge and active (t rp ) commands and between the active and read (t rcd ) commands. this is described in figure 16-6 on page 226 . sdcs d[15:0] (input) sdck sdramc_a[12:0] ras cas sdwe dna dnb dnc dnd dne dnf col a col b col c col d col e col f row n cas = 2 t rcd = 3
226 32072d?04/2011 at32uc3a3/a4 figure 16-6. read burst with boundary row access 16.7.5 sdram controller refresh cycles an auto refresh command is used to refresh the sdram device. refresh addresses are gener- ated internally by the sdram device and incr emented after each auto refresh automatically. the sdramc generates these auto refresh commands periodically. an internal timer is loaded with the value in the refresh timer register (tr) that indicates the number of clock cycles between successive refresh cycles. a refresh error interrupt is generated when the previous auto refresh command did not perform. in this case a refresh error status bit is set in the interrupt status register (isr.res). it is cleared by reading the isr register. when the sdramc initiates a refresh of the sdram device, internal memory accesses are not delayed. however, if the cpu tr ies to access the sdram, the slave indicates that the device is busy and the master is held by a wait signal. see figure 16-7 on page 227 . sdcs sdck sdramc_a[12:0] cas ras sdwe d[15:0] dna dnb dnc dnd dma dmb dmc dme dmd row m col a col b c ol c col d col e row n col a col b col c col d cas = 2 t rcd = 3 t rp = 3
227 32072d?04/2011 at32uc3a3/a4 figure 16-7. refresh cycle followed by a read access 16.7.6 power management three low power modes are available: ? self refresh mode: the sdram executes its own auto refresh cycles without control of the sdramc. current drained by the sdram is very low. ? power-down mode: auto refresh cycles are controlled by the sdramc. between auto refresh cycles, the sdram is in power-down. current drained in power-down mode is higher than in self refresh mode. ? deep power-down mode (only available with mobile sdram): the sdram contents are lost, but the sdram does not drain any current. the sdramc activates one low power mode as so on as the sdram device is not selected. it is possible to delay the entry in self refresh and power-down mode after the last access by config- uring the timeout field in the low power register (lpr.timeout). 16.7.6.1 self refresh mode this mode is selected by writing the value one to the low power configuration bits field in the sdramc low power register (l pr.lpcb). in self refresh mode, the sdram device retains data without external clocking and provides its own internal clocking, thus performing its own auto refresh cycles. all the inputs to the sdra m device become ?don?t care? except sdcke, which remains low. as soon as the sdram dev ice is selected, the sdramc provides a sequence of commands and exits self refresh mode. some low power sdrams (e.g., mobile sdram) can refresh only one quarter or a half quarter or all banks of the sdram array. this feature reduces the self refresh current. to configure this feature, temperature compensated self refresh (tcsr), partial array self refresh (pasr) sdcs sdck sdramc_a[12:0] row n col c col d ras cas sdwe d[15:0] (input) dnb dnc dnd dma col a row m cas = 2 t rcd = 3 t rc = 8 t rp = 3
228 32072d?04/2011 at32uc3a3/a4 and drive strength (ds) parameters must be set by writing the corresponding fields in the lpr register, and transmitted to the low po wer sdram device during initialization. after initialization, as soon as the lpr.pasr, lpr.ds, or lpr.tcsr fields are modified and self refresh mode is activated, the sdramc issues an extended load mode register command to the sdram and the extended mode register of the sdram device is accessed automati- cally. the pasr/ds/tcsr parameters values are therefore updated before entry into self refresh mode. the sdram device must remain in self refresh mode for a minimum period of t ras and may remain in self refresh mode for an indefinite period. this is described in figure 16-8 on page 228 . figure 16-8. self refresh mode behavior 16.7.6.2 low power mode this mode is selected by writing the value two to the lpr.lpcb field. power consumption is greater than in self refresh mode. all the i nput and output buffers of the sdram device are deactivated except sdcke, whic h remains low. in contrast to self refresh mode, the sdram device cannot remain in low power mode longer than the refresh period (64ms for a whole device refresh operation). as no auto refresh operations are performed by the sdram itself, the sdramc carries out the refresh operation. the exit procedure is faster than in self refresh mode. this is described in figure 16-9 on page 229 . sdramc_a[12:0] sdck sdcke sdcs ras cas access request to the sdram controller self refresh mode row t xsr = 3 sdwe
229 32072d?04/2011 at32uc3a3/a4 figure 16-9. low power mode behavior 16.7.6.3 deep power-down mode this mode is selected by writing the value three to the lpr.lpcb field. when this mode is acti- vated, all internal voltage generators inside the sdram are stopped and all data is lost. when this mode is enabled, the user must no t access to the sdram until a new initialization sequence is done (see section 16.7.1 ). this is described in figure 16-10 on page 230 . low power mode cas = 2 t rcd = 3 sdcs sdck sdramc_a[12:0] ras cas sdcke d[15:0] (input) dna dnb dnc dnd dne dnf col f col e col d col c col b col a row n
230 32072d?04/2011 at32uc3a3/a4 figure 16-10. deep power-down mode behavior sdcs sdck sdramc_a[12:0] ras cas sdwe scke d[15:0] (input) dnb dnc dnd col d col c row n t rp = 3
231 32072d?04/2011 at32uc3a3/a4 16.8 user interface table 16-5. sdramc register memory map offset register register name access reset 0x00 mode register mr read/write 0x00000000 0x04 refresh timer register tr read/write 0x00000000 0x08 configuration register cr read/write 0x852372c0 0x0c high speed register hsr read/write 0x00000000 0x10 low power register lpr read/write 0x00000000 0x14 interrupt enable register ier write-only 0x00000000 0x18 interrupt disable register idr write-only 0x00000000 0x1c interrupt mask register imr read-only 0x00000000 0x20 interrupt status register isr read-only 0x00000000 0x24 memory device register mdr read/write 0x00000000 0xfc version register version read-only - (1) 1. the reset values for these fields are de vice specific. please refer to the module conf iguration section at the end of this ch ap- ter.
232 32072d?04/2011 at32uc3a3/a4 16.8.1 mode register register name :mr access type : read/write offset: 0x00 reset value : 0x00000000 ? mode: command mode this field defines the command issued by t he sdramc when the sdram device is accessed. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 ----- mode mode description 0 normal mode. any access to the sdram is decoded normally. 1 the sdramc issues a ?nop? command when the sdram device is accessed regardless of the cycle. 2 the sdramc issues an ?all banks precharge? command when the sdram device is accessed regardless of the cycle. 3 the sdramc issues a ?load mode register? command wh en the sdram device is accessed regardless of the cycle. this command will load the cr.c as field into the sdram device mode register. all the other parameters of the sdram device mode register will be set to zero (burst length, burst type, operating mode, write burst mode...). 4 the sdramc issues an ?auto refres h? command when the sdram device is accessed regardless of the cycle. previously, an ?all banks precharge? command must be issued. 5 the sdramc issues an ?extended load mode register? command when the sdram device is accessed regardless of the cycle. this command will load the lpr.pasr, lpr.ds, and lpr.tcr fields into the sdram device extended mode register. all the other bits of th e sdram device extended mode register will be set to zero. 6 deep power-down mode. enters deep power-down mode.
233 32072d?04/2011 at32uc3a3/a4 16.8.2 refresh timer register register name :tr access type : read/write offset: 0x04 reset value : 0x00000000 ? count[11:0]: refresh timer count this 12-bit field is loaded into a timer that generates the refres h pulse. each time the refresh pulse is generated, a refresh burst is initiated. the value to be loaded depends on the sdramc clock frequency (clk_sdramc), the refresh rate of the sdram device and the refresh burst length where 15.6s per row is a typical value for a burst of length one. to refresh the sdram device, this 12-bit fiel d must be written. if this condition is not satisfied, no refresh command is issue d and no refresh of the sdram device is carried out. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - count[11:8] 76543210 count[7:0]
234 32072d?04/2011 at32uc3a3/a4 16.8.3 configuration register register name :cr access type : read/write offset: 0x08 reset value : 0x852372c0 ? txsr: exit self refr esh to active delay reset value is eight cycles. this field defines the delay between scke set high and an activate command in number of cycles. number of cycles is between 0 and 15. ? tras: active to precharge delay reset value is five cycles. this field defi nes the delay between an activate co mmand and a precharge command in numb er of cycles. number of cycles is between 0 and 15. ? trcd: row to column delay reset value is two cycles. this field defines the delay between an activate command and a r ead/write command in number of cycles. number of cycles is between 0 and 15. ? trp: row precharge delay reset value is three cycles. this field defines the delay between a pr echarge command and another command in number of cycles. number of cycles is between 0 and 15. ? trc: row cycle delay reset value is seven cycles. this field defines the delay between a refresh and an activate co mmand in number of cycles. number of cycles is between 0 and 15. ? twr: write recovery delay reset value is two cycles. this field defines the write recovery time in number of cycles. number of cycles is between 0 and 15. ? dbw: data bus width reset value is 16 bits. 0: reserved. 1: data bus width is 16 bits. 31 30 29 28 27 26 25 24 txsr tras 23 22 21 20 19 18 17 16 trcd trp 15 14 13 12 11 10 9 8 trc twr 76543210 dbw cas nb nr nc
235 32072d?04/2011 at32uc3a3/a4 ? cas: cas latency reset value is two cycles. in the sdramc, only a cas latency of one, two and three cycles is managed. ? nb: number of banks reset value is two banks. ? nr: number of row bits reset value is 11 row bits. ? nc: number of column bits reset value is 8 column bits. cas cas latency (cycles) 0reserved 11 22 33 nb number of banks 02 14 nr row bits 011 112 213 3reserved nc column bits 08 19 210 311
236 32072d?04/2011 at32uc3a3/a4 16.8.4 high speed register register name :hsr access type : read/write offset: 0x0c reset value: 0x00000000 ? da: decode cycle enable a decode cycle can be added on the addre sses as soon as a non-sequential access is performed on the hsb bus. the addition of the dec ode cycle allows the sdra mc to gain time to a ccess the sdram memory. 1: decode cycle is enabled. 0: decode cycle is disabled. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------da
237 32072d?04/2011 at32uc3a3/a4 16.8.5 low power register register name :lpr access type : read/write offset: 0x10 reset value : 0x00000000 ? timeout: time to define when low power mode is enabled ? ds: drive strength (only for low power sdram) this field is transmitted to the sdram during initialization to se lect the sdram strength of data output. this parameter must b e set according to the sdram device specification. after initialization, as soon as this field is modified and self refresh mode is activated, t he extended mode register of the sdram device is accessed automatically and its ds parameter value is updated before entry in self refresh mode. ? tcsr: temperature compensated self refresh (only for low power sdram) this field is transmitted to the sdram during initialization to set the refresh interval during self refresh mode depending on the temperature of the low power sdram. this parameter must be set according to the sdram device specification. after initialization, as soon as this field is modified and self refresh mode is activated, t he extended mode register of the sdram device is accessed autom atically and its tcsr parameter value is u pdated before entry in self refresh mode. ? pasr: partial array self refresh (only for low power sdram) this field is transmitted to the sdram during initialization to sp ecify whether only one quarter, one half or all banks of the sdram array are enabled. disabled banks are not refreshed in self refresh mode. this parameter must be set according to the sdram device specification. after initialization, as soon as this field is modified and self refresh mode is activated, t he extended mode register of the sdram device is accessed autom atically and its pasr parameter value is u pdated before entry in self refresh mode. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -- timeout ds tcsr 76543210 - pasr - - lpcb timeout time to define when low power mode is enabled 0 the sdramc activates the sdram low power mode i mmediately after the end of the last transfer. 1 the sdramc activates the sdram low power mode 64 clock cycles after the end of the last transfer. 2 the sdramc activates the sdram low power mode 128 clock cycles after the end of the last transfer. 3 reserved.
238 32072d?04/2011 at32uc3a3/a4 ? lpcb: low power configuration bits lpcb low power configuration 0 low power feature is inhibited: no power-down, self refresh or deep power-down command is issued to the sdram device. 1 the sdramc issues a self refresh command to the sdram device, the sdclk clock is deactivated and the sdcke signal is set low. the sdram device leaves the self refresh mode when accessed and enters it after the access. 2 the sdramc issues a power-down command to the sdram device after each access, the sdcke signal is set to low. the sdram device leaves the power-down mode when accessed and enters it after the access. 3 the sdramc issues a deep power-down command to the sdram device. this mode is unique to low- power sdram.
239 32072d?04/2011 at32uc3a3/a4 16.8.6 interrupt enable register register name :ier access type : write-only offset: 0x14 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will set the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------res
240 32072d?04/2011 at32uc3a3/a4 16.8.7 interrupt disable register register name :idr access type : write-only offset: 0x18 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------res
241 32072d?04/2011 at32uc3a3/a4 16.8.8 interrupt mask register register name :imr access type : read-only offset: 0x1c reset value: 0x00000000 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. a bit in this register is cleared when the corresponding bit in idr is written to one. a bit in this register is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------res
242 32072d?04/2011 at32uc3a3/a4 16.8.9 interrupt status register register name :isr access type : read-only offset: 0x20 reset value: 0x00000000 ? res: refresh error status this bit is set when a refresh error is detected. this bit is cleared when the register is read. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------res
243 32072d?04/2011 at32uc3a3/a4 16.8.10 memory device register register name :mdr access type : read/write offset: 0x24 reset value: 0x00000000 ? md: memory device type 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 ------ md md device type 0 sdram 1 low power sdram other reserved
244 32072d?04/2011 at32uc3a3/a4 16.8.11 version register register name : version access type : read-only offset: 0xfc reset value: - ? variant: variant number reserved. no functi onality associated. ? version: version number version number of the module.no functionality associated. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ---- variant 15 14 13 12 11 10 9 8 - - - - version 76543210 version
245 32072d?04/2011 at32uc3a3/a4 17. error corrected code controller (ecchrs) rev. 1.0.0.0 17.1 features ? hardware error corrected code generation with two methods : ? hamming code detection and correction by software (ecc-h) ? reed-solomon code detection by hardware, co rrection by hardware or software (ecc-rs) ? supports nand flash and smartmedia ? devices with 8- or 16-bit data path for ecc-h, and with 8-bit data path for ecc-rs ? supports nand flash and smartmedia ? with page sizes of 528, 1056, 2112, and 4224 bytes (specified by software) ? ecc_h supports : ? one bit correction per page of 512,1024,2048, or 4096 bytes ? one bit correction per sector of 512 bytes of da ta for a page size of 512, 1024, 2048, or 4096 bytes ? one bit correction per sector of 256 bytes of da ta for a page size of 512, 1024, 2048, or 4096 bytes ? ecc_rs supports : ? 4 errors correction per sector of 512 bytes of data for a page size of 512, 1024, 2048, and 4096 bytes with 8-bit data path 17.2 overview nand flash and smartmedia ? devices contain by default in valid blocks which have one or more invalid bits. over the nand flash and smartmedia ? lifetime, additional invalid blocks may occur which can be detected and corrected by an error corrected code (ecc). the ecc controller is a mechanism that encodes data in a manner that makes possible the identification and correction of certain errors in data. the ecc controller is capable of single-bit error correction and two-bit random detection when using the hamming code (ecc-h) and up to four symbols (a symbol is a 8-bit data) correction whatever the number of errors in symbol (1 to 8 bits of error) when using the reed-solomon code (ecc-rs). when nand flash/smartmedia ? have more than two erroneous bits when using the hamming code (ecc-h) or more than four bits in error when using the reed-solomon code (ecc-rs), the data cannot be corrected.
246 32072d?04/2011 at32uc3a3/a4 17.3 block diagram figure 17-1. ecchrs block diagram 17.4 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 17.4.1 i/o lines the ecchrs signals pass through the external bus interface module (ebi) where they are multiplexed. the programmer must first configure the i/o cont roller to assign the ebi pins corresponding to the static memory controller (smc) signals to their peripheral function. if i/o lines of the ebi corre- sponding to smc signals are not used by the application, they can be used for other purposes by the i/o controller. 17.4.2 power management if the cpu enters a sleep mode that disables clocks used by the ecchrs, the ecchrs will stop functioning and resume operation after the system wakes up from sleep mode. 17.4.3 clocks the clock for the ecchrs bus interface (clk_ecchrs) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to disable the ecchrs before disabling the clock, to avoid freezing the ecchrs in an undefined state. 17.4.4 interrupts the ecchrs interrupt request line is connected to the interrupt contro ller. using the ecchrs interrupt requires the interrupt controller to be programmed first. encoder rs4 polynomial process partial syndrome chien search error evaluator ctrl/ecc 1bit algorithm hecc user interface nand flash smartmedia logic static memory controller ecc controller peripheral bus rom 1024x10 gf(2 ) 10
247 32072d?04/2011 at32uc3a3/a4 17.5 functional description a page in nand flash and smartmedia ? memories contains an area for main data and an addi- tional area used for redundancy (ecc). the page is organized in 8-bit or 16-bit words. the page size corresponds to the number of words in the main area plus the number of words in the extra area used for redundancy. over time, some memory locations may fail to program or erase properly. in order to ensure that data is stored properly over the life of the nand flash device, nand flash providers recom- mend to utilize either one ecc per 256 bytes of data, one ecc per 512 bytes of data, or one ecc for all of the page. for the next generation of deep micron slc nand flash and with the new mlc nand flash, it is also recommended to ensure at least a four-error ecc per 512 bytes whatever is the page size. the only configurations required for ecc are the nand flash or the smartmedia ? page size (528/1056/2112/4224) and the type of correction wanted (one ecc-h for all the page, one ecc- h per 256 bytes of data, one ecc-h per 512 bytes of data, or four-error ecc-rs per 512 bytes of data). the page size is configured by writing in the page size field in the mode register (md.pagesize). type of correction is configured by writing the type of correction field in the mode register (md.typecorrec). the ecc is automatically computed as soon as a read (0x00) or a write (0x80) command to the nand flash or the smartmedia ? is detected. read and write access must start at a page boundary. the ecc results are available as soon as the counter reaches the end of the main area. the val- ues in the parity registers (pr0 to pr15) for ecc-h and in the codeword parity registers (cwps00 to cwps79) for ecc-rs are then valid and locked until a new start condition occurs (read/write command followed by address cycles). 17.5.1 write access once the flash memory page is written, the co mputed ecc codes are available in pr0 to pr15 registers for ecc-h and in cwps00 to cwps79 registers for ecc-rs. the ecc code values must be written by the software application in the extra area used for redundancy. the number of write access in the extra area depends on the value of the md.typecorrec field. for example, for one ecc per 256 bytes of data fo r a page of 512 bytes, only the values of pr0 and pr1 must be written by the software application in the extra area. for ecc-rs, a nand flash with page of 512 bytes, the software application will have to write the ten registers cwps00 to cwps09 in the extra area, and would have to write 40 registers (cwps00 to cwps39) for a nand flash with page of 2048 bytes. other registers are meaningless. 17.5.2 read access after reading the whole data in the main area, the application must perform read accesses to the extra area where ecc code has been previously stored. error detection is automatically per- formed by the ecc-h controller or the ecc-rs co ntroller. in ecc-rs, writing a one to the halt of computation bit in the ecc mode register (md.freeze) allows to stop error detection when software is jumping to the correct parity area.
248 32072d?04/2011 at32uc3a3/a4 figure 17-2. freeze signal waveform the application can check the ecc status regist ers (sr1/sr2) for any detected errors. it is up to the application to correct any detected erro r for ecc-h. the application can correct any detected error or let the hardware do the correction by writing a one to the correction enable bit in the md register (md.corrs4) for ecc-rs. ecc computation can detect four different circumstances: ? no error: xor between the ecc computation and the ecc code stored at the end of the nand flash or smartmedia ? page is equal to zero. all bits in the sr1 and sr2 registers will be cleared. ? recoverable error: only the recoverable error bits in the ecc status registers (sr1.recerrn and/or sr2.recerrn) are set. the corrupted word offset in the read page is defined by the word address field (wordaddr) in the pr0 to pr15 registers. the corrupted bit position in the concerned word is defined in the bit address field (bitaddr) in the pr0 to pr15 registers. ? ecc error: the ecc error bits in th e ecc status registers (sr1.eccerrn / sr2.eccerrn) are set. an error has been detected in the ecc code stored in the flash memory. the position of the corrupted bit can be found by the application performing an xor between the parity and the nparity contained in the ecc code stored in the flash memory. for ecc-rs it is the responsibility of the softwa re to determine where th e error is located on ecc code stored in the spare zone flash area and not on user data area. ? non correctable error: the multiple error bits (mulerrn) in the sr1 and sr2 registers are set. several unrecoverable errors have been detected in the flash memory page. ecc status registers, ecc parity registers are cleared when a read/write command is detected or a software reset is performed. for single-bit error correction and double-bit error detection (sec-ded) hsiao code is used. 24-bit ecc is generated in order to perform one bit correction per 256 or 512 bytes for pages of 512/2048/4096 8-bit words. 32-bit ecc is generated in order to perform one bit correction per 512/1024/2048/4096 8- or 16-bit words.they are generated according to the schemes shown in figure 17-3 on page 249 and figure 17-4 on page 250 . freeze spare zone nand flash page 2048b 512b 512b 512b 512b
249 32072d?04/2011 at32uc3a3/a4 figure 17-3. parity generation for 512/1024/2048/4096 8-bit words to calculate p8? to px? and p8 to px, apply the algorithm that follows. page size = 2 n for i =0 to n begin for (j = 0 to page_size_byte) begin if(j[i] ==1) p[2 i+3 ]=bit7(+)bit6(+)bit5(+)bit4(+)bit3(+) bit2(+)bit1(+)bit0(+)p[2 i+3 ] else p[2 i+3 ]?=bit7(+)bit6(+)bit5(+)bit4(+)bit3(+) bit2(+)bit1(+)bit0(+)p[2 i+3 ]' end end p8 p8' p16 p32 p8 p8' p16' p16 p32' p16' px px? bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 1 st byte 4 th byte 3 rd byte 2 nd byte (page size-3)th byte page size th byte (page size-1)th byte (page size-2)th byte bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 p8 p8' p8 p8' p1 p2 p1' p1 p1' p1 p1' p1 p1' p2' p2 p2' p4 p4' page size = 512 page size = 1024 page size = 2048 page size = 4096 px = 2048 px = 4096 px = 8192 px = 16384 p1=bit7(+)bit5(+)bit3(+)bit1(+)p1 p2=bit7(+)bit6(+)bit3(+)bit2(+)p2 p4=bit7(+)bit6(+)bit5(+)bit4(+)p4 p1'=bit6(+)bit4(+)bit2(+)bit0(+)p1' p2'=bit5(+)bit4(+)bit1(+)bit0(+)p2' p4'=bit7(+)bit6(+)bit5(+)bit4(+)p4'
250 32072d?04/2011 at32uc3a3/a4 figure 17-4. parity generation for 512/1024/2048/4096 16-bit words to calculate p8? to px? and p8 to px, apply the algorithm that follows. page size = 2 n for i =0 to n begin for (j = 0 to page_size_word) begin if(j[i] ==1) p[2 i+3 ]= bit15(+)bit14(+)bit13(+)bit12(+) bit11(+)bit10(+)bit9(+)bit8(+) bit7(+)bit6(+)bit5(+)bit4(+)bit3(+) bit2(+)bit1(+)bit0(+)p[2 n+3 ] else p[2 i+3 ]?=bit15(+)bit14(+)bit13(+)bit12(+) bit11(+)bit10(+)bit9(+)bit8(+) bit7(+)bit6(+)bit5(+)bit4(+)bit3(+) bit2(+)bit1(+)bit0(+)p[2 i+3 ]' end end p8 p8' p16 p32 p8 p8' p16' p16 p32' p16' px px? p8 p8' p8 p8' page size = 512 page size = 1024 page size = 2048 page size = 4096 px = 2048 px = 4096 px = 8192 px = 16384 p1=bit15(+)bit13(+)bit11(+)bit9(+)bit7(+)bit5(+)bit3(+)bit1(+)p1 p2=bit15(+)bit14(+)bit11(+)bit10(+)bit7(+)bit6(+)bit3(+)bit2(+)p2 p4=bit15(+)bit14(+)bit13(+)bit12(+)bit7(+)bit6(+)bit5(+)bit4(+)p4 p5=bit15(+)bit14(+)bit13(+)bit12(+)bit11(+)bit10(+)bit9(+)bit8(+)p5 bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 1 st byte 4 th byte 3 rd byte 2 nd byte (page size-3)th byte page size th byte (page size-1)th byte (page size-2)th byte bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 p1 p2 p1' p1 p1' p1 p1' p1 p1' p2' p2 p2' p4 p4' bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 p1 p2 p1' p1 p1' p1 p1' p1 p1' p2' p2 p2' p4 p4' bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 p5 p5'
251 32072d?04/2011 at32uc3a3/a4 for ecc-rs, in order to perform 4-error correction per 512 bytes of 8-bit words, the codeword have to be generated by the rs4 encoder module and stored into the nand flash extra area, according to the scheme shown in figure 17-5 on page 251 figure 17-5. rs codeword generation in read mode, firstly, the detection for any error is done with the partial syndrome module. it is the responsibility of the ecc-rs controller to determine after receiving the ol d codeword stored in the extra area if there is any error on data and /or on the old codeword. if all syndromes (si) are equal to zero, there is no error, otherwise a polynomial representation is written into cwps00 to cwps79 registers. the partial syndrome module performs an algorithm according to the scheme in figure 17-6 on page 251 figure 17-6. partial syndrome block diagram if the correction enable bit is set in the ecc mode register (md.corrs4) then the polynomial representation of error are sent to the polynomial processor. the aim of this module is to per- form the polynomial division in order to calc ulate two polynomials, omega (z) and lambda (z), which are necessary for the two following modules (chien search and error evaluator). in order to perform addition, multiplication, and division a read only memory (rom) has been added containing the 1024 elements of the galois field. both chien search and error evaluator work in parallel. the error evaluator has the responsibility to determine the nth error value in the data and in the old codeword according to the scheme in figure 17-7 on page 252 cw7 cw6 cw5 cw4 cw3 cw2 cw1 cw0 + + + + + + + + 500 28 397 402 603 395 383 539 feedback datain x datain(x) x mu l t regoct x i s0 s1 s2 s7
252 32072d?04/2011 at32uc3a3/a4 figure 17-7. error evaluator block diagram the chien search takes charge of determining if an error has occurred at symbol n according to the scheme in figure 17-8 on page 252 figure 17-8. chien search block diagram 0 4 1 5 3 7 + -4 -1 -3 -5 -7 array - mult rom 1024x10 gf(2 ) inverted odd( ) -j 10 errorloc error value @ position j ( ) -j 0 not error located counter deg ree of lambda error located flag er ror + + + 0 1 2 3 8 7 ( ) -j -1 -2 -8 -3 -7 odd( ) -j
253 32072d?04/2011 at32uc3a3/a4 17.6 user interface note: 1. the reset value is device specific. please refer to th e module configuration section at the end of this chapter. table 17-1. ecchrs register memory map offset register name access reset 0x000 control register ctrl write-only 0x00000000 0x004 mode register md read/write 0x00000000 0x008 status register 1 sr1 read-only 0x00000000 0x00c parity register 0 pr0 read-only 0x00000000 0x010 parity register 1 pr1 read-only 0x00000000 0x014 status register 2 sr2 read-only 0x00000000 0x018 parity register 2 pr2 read-only 0x00000000 0x01c parity register 3 pr3 read-only 0x00000000 0x020 parity register 4 pr4 read-only 0x00000000 0x024 parity register 5 pr5 read-only 0x00000000 0x028 parity register 6 pr6 read-only 0x00000000 0x02c parity register 7 pr7 read-only 0x00000000 0x030 parity register 8 pr8 read-only 0x00000000 0x034 parity register 9 pr9 read-only 0x00000000 0x038 parity register 10 pr10 read-only 0x00000000 0x03c parity register 11 pr11 read-only 0x00000000 0x040 parity register 12 pr12 read-only 0x00000000 0x044 parity register 13 pr13 read-only 0x00000000 0x048 parity register 14 pr14 read-only 0x00000000 0x04c parity register 15 pr15 read-only 0x00000000 0x050 - 0x18c codeword and syndrome 00 - codeword and syndrome 79 cwps00 - cwps79 read-only 0x00000000 0x190 - 0x19c maskdata 0 - mask data 3 mdata0 - mdata3 read-only 0x00000000 0x1a0 - 0x1ac address offset 0 - address offset 3 adoff0 - adoff3 read-only 0x00000000 0x1b0 interrupt enable register ier write-only 0x00000000 0x1b4 interrupt disable register idr write-only 0x00000000 0x1b8 interrupt mask register mr read-only 0x00000000 0x1bc interrupt status register isr read-only 0x00000000 0x1c0 interrupt status clear register iscr write-only 0x00000000 0x1fc version register version read-only - (1)
254 32072d?04/2011 at32uc3a3/a4 17.6.1 control register name: cr access type: write-only offset :0x000 reset value : 0x00000000 ? rst: reset parity writing a one to this bit will reset the ecc parity registers. writing a zero to this bit has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------rst
255 32072d?04/2011 at32uc3a3/a4 17.6.2 mode register name: md access type: read/write offset :0x004 reset value : 0x00000000 ? corrs4: correction enable writing a one to this bit will enable the correction to be done after the partial syndrome process and allow interrupt to be se nt to cpu. writing a zero to this bit will stop the correction after the partial syndrome process. 1: the correction will continue after the partial syndrome process. 0: the correction will stop after the partial syndrome process. ? freeze: halt of computation writing a one to this bit will stop the computation. writing a zero to this bit will allow the computation as so on as read/write command to the nand flash or the smartmedia ? is detected. 1: the computation will stop until a zero is written to this bit. 0: the computation is allowed. ? typecorrec: type of correction 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -----corrs4-freeze 76543210 - typecorrec - pagesize ecc code typecorrec description ecc-h 0b000 one bit correction per page 0b001 one bit correction per sector of 256 bytes 0b010 one bit correction per sector of 512 bytes ecc-rs 0b100 four bits correction per sector of 512 bytes - others reserved
256 32072d?04/2011 at32uc3a3/a4 ? pagesize: page size this table defines the page size of the nand flash device when using th e ecc-h code (typecorrec = 0b0xx). a word has a value of 8 bits or 16 bits, depending on the nand flash or smartmedia ? memory organization. this table defines the page size of the nand flash device when using the ecc-rs code (typecorrec = 0b1xx) i.e.: for nand flash device with page size of 4096 bytes and 128 bytes extra area ecc-rs can manage any sub page of 512 bytes up to 8. page size description 0 528 words 1 1056 words 2 2112 words 3 4224 words others reserved page size description comment 0 528 bytes 1 page of 512 bytes 1 1056 bytes 2 pages of 512 bytes 2 1584 bytes 3 pages of 512 bytes 3 2112 bytes 4 pages of 512 bytes 4 2640 bytes 5 pages of 512 bytes 5 3168 bytes 6 pages of 512 bytes 6 3696 bytes 7 pages of 512 bytes 7 4224 bytes 8 pages of 512 bytes
257 32072d?04/2011 at32uc3a3/a4 17.6.3 status register 1 name: sr1 access type: read-only offset :0x008 reset value : 0x000000000 md.typecorrec=0b0xx, using ecc-h code ? mulerrn: multiple error in the sector number n of 256/512 bytes in the page 1: multiple errors are detected. 0: no multiple error is detected. ? eccerrn: ecc error in the packet number n of 256/512 bytes in the page 1: a single bit error has occurred. 0: no error have been detected. 31 30 29 28 27 26 25 24 - mulerr7 eccerr7 recerr7 - mulerr6 eccerr6 recerr6 23 22 21 20 19 18 17 16 - mulerr5 eccerr5 recerr5 - mulerr4 eccerr4 recerr4 15 14 13 12 11 10 9 8 - mulerr3 eccerr3 recerr3 - mulerr2 eccerr2 recerr2 76543210 - mulerr1 eccerr1 recerr1 - mulerr0 eccerr0 recerr0 typecorrec sector size comments 0 page size only mulerr0 is used 1 256 mulerr0 to mulerr7 are used depending on the page size 2 512 mulerr0 to mulerr7 are used depending on the page size others reserved typecorrec sector size comments 0 page size only eccerr0 is used the user should read pr0 and pr1 to know where the error occurs in the page. 1 256 eccerr0 to eccerr7 are used depending on the page size 2 512 eccerr0 to eccerr7 are used depending on the page size others reserved
258 32072d?04/2011 at32uc3a3/a4 ? recerrn: recoverable error in the packet number n of 256/512 bytes in the page 1: errors detected. if mulerrn is zero, a single correctable error wa s detected. otherwise multiple uncorrected errors were detected. 0: no errors have been detected. md.typecorrec=0b1xx, using ecc-rs code ? synvec: syndrome vector after reading a page made of n sector of 512 bytes, this field returns which sector contains error detected after the syndrome analysis. the synvec[n] bit is set when there is at least one error in the corresponding sector. the synvec[n] bit is cleared when a read/write command is detected or a software reset is performed. 1: at least one error has occurred in the corresponding sector. 0: no error has been detected. typecorrec sector size comments 0 page size only recerr0 is used 1 256 recerr0 to recerr7 are used depending on the page size 2 512 recerr0 to recerr7 are used depending on the page size others reserved 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 synvec bit index (n) sector boundaries 00-511 1 512-1023 2 1023-1535 3 1536-2047 4 2048-2559
259 32072d?04/2011 at32uc3a3/a4 5 2560-3071 6 3072-3583 7 3584-4095 bit index (n) sector boundaries
260 32072d?04/2011 at32uc3a3/a4 17.6.4 parity register 0 name: pr0 access type: read-only offset :0x00c reset value : 0x00000000 using ecc-h code, one bit correcti on per page (md.typecorrec=0b000) once the entire main area of a page is written with data, this register content must be stored at any free location of the spar e area. ? wordaddr: word address during a page read, this field contains the word address (8-bit or 16-bit word, depending on the memory plane organization) where an error occurred, if a single error was detected. if multiple errors were detected, this field is meaningless. ? bitaddr: bit address during a page read, this field contains th e corrupted bit offset where an error occurred , if a single error was detected. if mu ltiple errors were detected, th is field is meaningless. using ecc-h code, one bit co rrection per sector of 256 bytes (m d.typecorrec=0b001) 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 wordaddr[11:4] 76543210 wordaddr[3:0] bitaddr 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - nparity0[10:4] 15 14 13 12 11 10 9 8
261 32072d?04/2011 at32uc3a3/a4 once the entire main area of a page is written with data, this register content must be stored at any free location of the spar e area. ? nparity0: parity n parity calculated by the ecc-h. ? wordaddr0: corrupted word address in the page between the first byte and the 255th byte during a page read, this field contains the word address (8-bit wo rd) where an error occurred, if a single error was detected. if multiple errors were detected, this field is meaningless. ? bitaddr0: corrupted bit address in the page between the first byte and the 255th byte during a page read, this field contains th e corrupted bit offset where an error occurred , if a single error was detected. if mu ltiple errors were detected, th is field is meaningless. nparity0[3:0] 0 wordadd0[7:5] 76543210 wordadd0[4:0] bitaddr0
262 32072d?04/2011 at32uc3a3/a4 using ecc-h code, one bit co rrection per sector of 512 bytes (m d.typecorrec=0b010) once the entire main area of a page is written with data, this register content must be stored at any free location of the spar e area. ? nparity0: parity n parity calculated by the ecc-h. ? wordaddr0: corrupted word address in the page between the first byte and the 511th byte during a page read, this field contains the word address (8-bit wo rd) where an error occurred, if a single error was detected. if multiple errors were detected, this field is meaningless. ? bitaddr0: corrupted bit address in the page between the first byte and the 511th byte during a page read, this field contains th e corrupted bit offset where an error occurred , if a single error was detected. if mu ltiple errors were detected, th is field is meaningless. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 nparity0[11:4] 15 14 13 12 11 10 9 8 nparity0[3:0] wordadd0[8:5] 76543210 wordadd0[4:0] bitaddr0
263 32072d?04/2011 at32uc3a3/a4 17.6.5 parity register 1 name: pr1 access type: read-only offset :0x010 reset value : 0x00000000 using ecc-h code, one bit correcti on per page (md.typecorrec=0b000) ? nparity: parity n during a write, the field of this register must be written in the extra area used for redundancy (for a 512-byte page size: address 514-515). using ecc-h code, one bit co rrection per sector of 256 bytes (m d.typecorrec=0b001) 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 nparity[15:8] 76543210 nparity[7:0] 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - nparity1[10:0] 15 14 13 12 11 10 9 8 nparity1[3:0] 0 wordadd1[7:5] 76543210 wordadd1[4:0] bitaddr1
264 32072d?04/2011 at32uc3a3/a4 once the entire main area of a page is written with data, this register content must be stored at any free location of the spar e area. ? nparity1: parity n parity alculated by the ecc-h. ? wordaddr1: corrupted word address in the page between the 256th and the 511th byte during a page read, this field contains the word address (8-bit wo rd) where an error occurred, if a single error was detected. if multiple errors were detected, this field is meaningless. ? bitaddr1: corrupted bit address in the pa ge between the 256th and the 511th byte during a page read, this field contains th e corrupted bit offset where an error occurred , if a single error was detected. if mu ltiple errors were detected, th is field is meaningless. using ecc-h code, one bit co rrection per sector of 512 bytes (m d.typecorrec=0b010) once the entire main area of a page is written with data, this register content must be stored at any free location of the spar e area. ? nparity1: parity n parity calculated by the ecc-h. ? wordaddr1: corrupted word address in the page between the 512th and the 1023th byte during a page read, this field contains the word address (8-bit wo rd) where an error occurred, if a single error was detected. if multiple errors were detected, this field is meaningless. ? bitaddr1: corrupted bit addres s in the page between the 512th and the 1023th byte during a page read, this field contains th e corrupted bit offset where an error occurred , if a single error was detected. if mu ltiple errors were detected, th is field is meaningless. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 nparity1[11:4] 15 14 13 12 11 10 9 8 nparity1[3:0] wordadd1[8:5] 76543210 wordadd1[4:0] bitaddr1
265 32072d?04/2011 at32uc3a3/a4 17.6.6 status register 2 name: sr2 access type: read-only offset :0x014 reset value : 0x00000000 md.typecorrec=0b0xx, using ecc-h code ? mulerrn: multiple error in the sector number n of 256/512 bytes in the page 1: multiple errors are detected. 0: no multiple error is detected. ? eccerrn: ecc error in the packet number n of 256/512 bytes in the page 1: a single bit error has occurred. 0: no error is detected. 31 30 29 28 27 26 25 24 - mulerr15 eccerr15 recerr15 - mulerr14 eccerr14 recerr14 23 22 21 20 19 18 17 16 - mulerr13 eccerr13 recerr13 - mulerr12 eccerr12 recerr12 15 14 13 12 11 10 9 8 - mulerr11 eccerr11 recerr11 - mulerr10 eccerr10 recerr10 76543210 - mulerr9 eccerr9 recerr9 - mulerr8 eccerr8 recerr8 typecorrec sector size comments 0 page size only mulerr0 is used 1 256 mulerr0 to mulerr7 are used depending on the page size 2 512 mulerr0 to mulerr7 are used depending on the page size others reserved typecorrec sector size comments 0 page size only eccerr0 is used the user should read pr0 and pr1 to know where the error occurs in the page. 1 256 eccerr0 to eccerr7 are used depending on the page size 2 512 eccerr0 to eccerr7 are used depending on the page size others reserved
266 32072d?04/2011 at32uc3a3/a4 md.typecorrec=0b1xx, using ecc-rs code only one sub page of 512 bytes is corrected at a time. if several sub page are on error then it is necessary to do several time the correction process. ? mulerr: multiple error this bit is set to one when a multiple error have been detected by the ecc-rs. this bit is cleared when a read/write command is detected or a software reset is performed. 1: multiple errors detected: more than four errors.r egisters for one ecc for a page of 512/1024/2048/4096 bytes 0: no multiple error detected ? recerr: number of recoverable errors if mulerr is zero 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - - - mulerr recerr recerr comments 000 no error 001 one single error detected 010 two errors detected 011 three errors detected 100 four errors detected
267 32072d?04/2011 at32uc3a3/a4 17.6.7 parity register 2 - 15 name: pr2 - pr15 access type: read-only offset : 0x018 - 0x04c reset value : 0x00000000 using ecc-h code, one bit co rrection per sector of 256 bytes (m d.typecorrec=0b001) once the entire main area of a page is written with data, this register content must be stored at any free location of the spar e area. ? nparityn: parity n parity calculated by the ecc-h. ? wordaddrn: corrupted word address in the packet number n of 256 bytes in the page during a page read, this field contains the word address (8-bit wo rd) where an error occurred, if a single error was detected. if multiple errors were detected, this field is meaningless. ? bitaddrn: corrupted bit address in the pack et number n of 256 bytes in the page during a page read, this field contains th e corrupted bit offset where an error occurred , if a single error was detected. if mu ltiple errors were detected, th is field is meaningless. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - nparityn[10:4] 15 14 13 12 11 10 9 8 nparityn[3:0] 0 wordaddn[7:5] 76543210 wordaddn[4:0] bitaddrn
268 32072d?04/2011 at32uc3a3/a4 using ecc-h code, one bit co rrection per sector of 512 bytes (m d.typecorrec=0b010) once the entire main area of a page is written with data, this register content must be stored to any free location of the spar e area. only pr2 to pr7 registers are available in this case. ? nparityn: parity n parity calculated by the ecc-h. ? wordaddrn: corrupted word address in the packet number n of 512 bytes in the page during a page read, this field contains the word address (8-bit wo rd) where an error occurred, if a single error was detected. if multiple errors were detected, this field is meaningless. ? bitaddrn: corrupted bit address in the pack et number n of 512 bytes in the page during a page read, this field contains th e corrupted bit offset where an error occurred , if a single error was detected. if mu ltiple errors were detected, th is field is meaningless. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 nparityn[11:4] 15 14 13 12 11 10 9 8 nparityn[3:0] wordaddn[8:5] 76543210 wordaddn[4:0] bitaddrn
269 32072d?04/2011 at32uc3a3/a4 17.6.8 codeword 00 - codeword79 name: cwps00 - cwps79 access type: read-only offset: 0x050 - 0x18c reset value: 0x00000000 page write: ? codeword: once the 512 bytes of a page is written with data, this register content must be stored to any free location of the spare area. for a page of 512 bytes the entire redundancy words are made of 8 words of 10 bits. all those redundancies words are concatenated to a word of 80 bits and then cut to 10 word s of 8 bits to facilitate their writing in the extra area. at the end of a page write, this field contains t he redundancy word to be stored to the extra area. page read: 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 codeword 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 parsynd
270 32072d?04/2011 at32uc3a3/a4 ? parsynd: at the end of a page read, this field contains the partial syndrome s. parsynd00-parsynd09: this conclude all the codeword and partial syndrome word for the sub page 1 parsynd10-parsynd19: this conclude all the codeword and partial syndrome word for the sub page 2 parsynd20-parsynd29: this conclude all the codeword and partial syndrome word for the sub page 3 parsynd30-parsynd39: this conclude all the codeword and partial syndrome word for the sub page 4 parsynd40-parsynd49: this conclude all the codeword and partial syndrome word for the sub page 5 parsynd50-parsynd59: this conclude all the codeword and partial syndrome word for the sub page 6 parsynd60-parsynd69: this conclude all the codeword and partial syndrome word for the sub page 7 parsynd70-parsynd79: this conclude all the codeword and partial syndrome word for the sub page 8
271 32072d?04/2011 at32uc3a3/a4 17.6.9 mask data 0 - mask data 3 name: mdata0 -mdata3 access type: read-only offset: 0x190 - 0x19c reset value: 0x00000000 ? maskdata: at the end of the correction process, this field contains t he mask to be xored with the data read to perform the final correction.this xored is under t he responsibility of the software. this field is meaningless if md.corrs4 is zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - - - maskdata[9:8] 76543210 maskdata[7:0]
272 32072d?04/2011 at32uc3a3/a4 17.6.10 address offset 0 - address offset 3 name: adoff0 - adoff3 access type: read-only offset: 0x1a0 - 0x1ac reset value: 0x00000000 ? offset: at the end of correction process, this field contains the offset address of the data read to be corrected. this field is meaningless if md.corrs4 is zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 ------ offset[9:8] 76543210 offset[7:0]
273 32072d?04/2011 at32uc3a3/a4 17.6.11 interrupt enable register name: ier access type: write-only offset: 0x1b0 reset value: 0x00000000 ? endcor: writing a zero to this bit has no effect. writing a one to this bit will set the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------endcor
274 32072d?04/2011 at32uc3a3/a4 17.6.12 interrupt disable register name: idr access type: write-only offset: 0x1b4 reset value: 0x00000000 ? endcor: writing a zero to this bit has no effect. writing a one to this bit will clear the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 ------- 76543210 -------endcor
275 32072d?04/2011 at32uc3a3/a4 17.6.13 interrupt mask register name: imr access type: read-only offset: 0x1b8 reset value: 0x00000000 ? endcor: 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. this bit is cleared when the corresponding bit in idr is written to one. this bit is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------endcor
276 32072d?04/2011 at32uc3a3/a4 17.6.14 interrupt status register name: isr access type: read-only offset :0x1bc reset value : 0x00000000 ? endcor: this bit is cleared when the corresponding bit in iscr is written to one. this bit is set when a correction process has ended. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ----- 15 14 13 12 11 10 9 8 -------- 76543210 -------endcor
277 32072d?04/2011 at32uc3a3/a4 17.6.15 interrupt status clear register name: iscr access type: write-only offset :0x1c0 reset value : 0x00000000 ? endcor: writing a zero to this bit has no effect writing a one to this bit will clear the corresponding bit in isr and the corresponding interrupt request. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ----- 15 14 13 12 11 10 9 8 -------- 76543210 -------endcor
278 32072d?04/2011 at32uc3a3/a4 17.6.16 version register name: version access type: read-only offset :0x1fc reset value : 0x00000000 ? variant: variant number reserved. no functionality associated. ? version: version number version number of the module. no functionality associated. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ----- variant 15 14 13 12 11 10 9 8 - - - - version[11:8] 76543210 version[7:0]
279 32072d?04/2011 at32uc3a3/a4 17.7 module configuration the specific configuration for the ecchrs instan ce is listed in the fo llowing tables.the module bus clocks listed here are connected to the system bus clocks according to the table in the power manager section. table 17-2. module clock name module name clock name ecchrs clk_ecchrs table 17-3. register reset values register reset value version 0x00000100
280 32072d?04/2011 at32uc3a3/a4 18. peripheral dma controller (pdca) rev: 1.1.0.1 18.1 features ? multiple channels ? generates transfers between memories and peripherals such as usart and spi ? two address pointers/counters per ch annel allowing double buffering ? performance monitors to measure average and maximum transfer latency 18.2 overview the peripheral dma controller (pdca) transfers data between on-chip peripheral modules such as usart, spi and memories (those memories ma y be on- and off-chip memories). using the pdca avoids cpu intervention for data transfers, improving the performance of the microcon- troller. the pdca can transfer data from memory to a peripheral or from a peripheral to memory. the pdca consists of multiple dma channels. each channel has: ? a peripheral select register ? a 32-bit memory pointer ? a 16-bit transfer counter ? a 32-bit memory pointer reload value ? a 16-bit transfer counter reload value the pdca communicates with the peripheral modules over a set of handshake interfaces. the peripheral signals the pdca when it is ready to receive or transmit data. the pdca acknowl- edges the request when the transmission has started. when a transmit buffer is empty or a receive buffer is full, an optional interrupt request can be generated.
281 32072d?04/2011 at32uc3a3/a4 18.3 block diagram figure 18-1. pdca block diagram 18.4 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 18.4.1 power management if the cpu enters a sleep mode that disables the pdca clocks, the pdca will stop functioning and resume operation after the system wakes up from sleep mode. 18.4.2 clocks the pdca has two bus clocks connected: one high speed bus clock (clk_pdca_hsb) and one peripheral bus clock (clk_pdca_pb). thes e clocks are generated by the power man- ager. both clocks are enabled at reset, and can be disabled by wr iting to the power manager. it is recommended to disable the pdca before disa bling the clocks, to avoid freezing the pdca in an undefined state. 18.4.3 interrupts the pdca interrupt request lines are connected to the interrupt controller. using the pdca interrupts requires the interrupt controller to be programmed first. hsb to pb bridge peripheral dma controller (pdca) peripheral 0 high speed bus matrix handshake interfaces peripheral bus irq hsb hsb interrupt controller peripheral 1 peripheral 2 peripheral (n-1) ... memory hsb
282 32072d?04/2011 at32uc3a3/a4 18.5 functional description 18.5.1 basic operation the pdca consists of multiple independent pdca channels, each capable of handling dma requests in parallel. each pdca channels contains a set of configuration registers which must be configured to start a dma transfer. in this section the steps necessary to configure one pdca channel is outlined. the peripheral to transfer data to or from must be configured correctly in the peripheral select register (psr). this is performed by writing the peripheral identity (pid) value for the corre- sponding peripheral to the pid field in the ps r register. the pid also encodes the transfer direction, i.e. memory to peripheral or peripheral to memory. see section 18.5.5 . the transfer size must be written to the transfer size field in the mode register (mr.size). the size must match the data size produced or consumed by the selected peripheral. see section 18.5.6 . the memory address to transfer to or from, depending on the psr, must be written to the mem- ory address register (mar). for each transfer the memory address is increased by either a one, two or four, depending on the size set in mr. see section 18.5.2 . the number of data items to transfer is written to the tcr register. if the pdca channel is enabled, a transfer will start imm ediately after writing a non-zero value to tc r or the reload ver- sion of tcr, tcrr. after each transfer the tcr value is decreased by one. both mar and tcr can be read while the pdca channel is active to monitor the dma progress. see section 18.5.3 . the channel must be enabled for a transfer to start. a channel is enable by writing a one to the en bit in the control register (cr). 18.5.2 memory pointer each channel has a 32-bit memory address regi ster (mar). this register holds the memory address for the next transfer to be performed. the register is automatically updated after each transfer. the address will be increa sed by either one, two or four depending on the size of the dma transfer (byte, halfword or word). the mar can be read at any time during transfer. 18.5.3 transfer counter each channel has a 16-bit transfer counter register (tcr). this register must be programmed with the number of transfers to be performed. the tcr register should contain the number of data items to be transferred independently of the transfer size. the tcr can be read at any time during transfer to see the number of remaining transfers. 18.5.4 reload registers both the mar and the tcr have a reload regist er, respectively memory address reload regis- ter (marr) and transfer counter reload register (tcrr). these registers provide the possibility for the pdca to work on two memory buffer s for each channel. when one buffer has completed, mar and tcr will be re loaded with the values in marr and tcrr. the reload logic is always enabled and will trigger if the tcr reaches zero while tcrr holds a non-zero value. after reload, the marr and tcrr registers are cleared. if tcr is zero when writing to tcrr, the tcr and mar are automatically updated with the value written in tcrr and marr.
283 32072d?04/2011 at32uc3a3/a4 18.5.5 peripheral selection the peripheral select register (psr) decides which peripheral should be connected to the pdca channel. a peripheral is selected by writing the corresponding peripheral identity (pid) to the pid field in the psr register. writing the pid will both select the direction of the transfer (memory to peripheral or peripheral to memory ), which handshake interface to use, and the address of the peripheral holding register. refer to the peripheral identity (pid) table in the mod- ule configuration section for the peripheral pid values. 18.5.6 transfer size the transfer size can be set individually for each channel to be either byte, halfword or word (8- bit, 16-bit or 32-bit respectively). transfer size is set by writing the desired value to the transfer size field in the mode register (mr.size). when the pdca moves data between peripherals and memory, data is automatically sized and aligned. when memory is accessed, the size specified in mr.size and system alignment is used. when a peripheral register is accessed t he data to be transferred is converted to a word where bit n in the data corresponds to bit n in the peripheral register. if the transfer size is byte or halfword, bits greater than 8 and16 respectively are set to zero. refer to the module configuration section for information regarding what peripheral registers are used for the different peripherals and then to the peripheral specific chapter for information about the size option available for the different registers. 18.5.7 enabling and disabling each dma channel is enabled by writing a one to the transfer enable bit in the control register (cr.ten) and disabled by writing a one to the transfer disable bit (cr.tdis). the current sta- tus can be read from the status register (sr). while the pdca channel is enabled all dma re quest will be handled as long the tcr and tcrr is not zero. 18.5.8 interrupts interrupts can be enabled by writing a one to the corresponding bit in the interrupt enable regis- ter (ier) and disabled by writing a one to the corresponding bit in the interrupt disable register (idr). the interrupt mask register (imr) can be read to see whether an interrupt is enabled or not. the current status of an interrupt source can be read through the interrupt status register (isr). the pdca has three interrupt sources: ? reload counter zero - the tcrr register is zero. ? transfer finished - both the tcr and tcrr registers are zero. ? transfer error - an error has occurred in accessing memory. 18.5.9 priority if more than one pdca channel is requesting transfer at a given time, the pdca channels are prioritized by their channel number. channels wi th lower numbers have priority over channels with higher numbers, giving channel zero the highest priority. 18.5.10 error handling if the memory address register (mar) is set to point to an invalid location in memory, an error will occur when the pdca tries to perform a transfer. when an error occurs, the transfer error
284 32072d?04/2011 at32uc3a3/a4 bit in the interrup t status register (isr.terr) will be se t and the dma channel that caused the error will be stopped. in order to restart the channel, the user must program the memory address register to a valid address and then write a one to the error clear bit in the control register (cr.eclr). if the transfer error interrupt is enabled , an interrupt request will be gener- ated when an transfer error occurs. 18.6 performance monitors up tp two performance monitors allow the user to measure the activity and stall cycles for pdca transfers. to monitor a pdca channel, the corresponding channel number must be written to one of the monnch fields in the performance control register (pcontrol) and a one must be written to the corresponding chnen bit in the same register. due to performance monitor hardware resource sharing, the two monitor channels should not be programmed to monitor the same pdca channel. this may result in undefined perfor- mance monitor behavior. 18.6.1 measuring mechanisms three different parameters can be measured by each channel: ? the number of data transfer cycles since last channel reset, both for read and write ? the number of stall cycles since last channel reset, both for read and write ? the maximum latency since last channel reset, both for read and write these measurements can be extracted by soft ware and used to generate indicators for bus latency, bus load, and maximum bus latency. each of the counters has a fixed width, and may therefore overflow. when an overflow is encountered in either the performance channel data read/write cycle registers (prdatan and pwdatan) or the performance channel read/write stall cycles registers (prstalln and pwstalln) of a channel, all registers in the channel are reset. this behavior is altered if the channel overflow freeze bit is one in the performance control register (pcontrol.chnovf). if this bit is one, the channel registers are fr ozen when either data or stall reaches its maxi- mum value. this simplifies one-shot readout of the counter values. the registers can also be manually reset by writing a one to the channel reset bit in the pcon- trol register (pcontrol.chnres). the performance channel read/write latency registers (prlatn and pwlatn) are saturating when their maximum count value is reached. the prlatn and pwlatn registers are rese t only by writing a one to the chnres in pcontrol. a counter must manually be enabled by writing a one to the channel enable bit in the perfor- mance control register (pcontrol.chnen).
285 32072d?04/2011 at32uc3a3/a4 18.7 user interface 18.7.1 memory map overview the channels are mapped as shown in table 18-1 . each channel has a set of configuration reg- isters, shown in table 18-2 , where n is the channel number. 18.7.2 channel memory map note: 1. the reset values are device specific. please refer to the module config uration section at the end of this chapter. table 18-1. pdca register memory map address range contents 0x000 - 0x03f dma channel 0 configuration registers 0x040 - 0x07f dma channel 1 configuration registers ... ... (0x000 - 0x03f)+m*0x040 dma channel m configuration registers 0x800-0x830 performance monitor registers 0x834 version register table 18-2. pdca channel configuration registers offset register register name access reset 0x000 + n*0x040 memory address register mar read/write 0x00000000 0x004 + n*0x040 peripheral select register psr read/write - (1) 0x008 + n*0x040 transfer counter register tcr read/write 0x00000000 0x00c + n*0x040 memory address reload register marr read/write 0x00000000 0x010 + n*0x040 transfer counter reload register tcrr read/write 0x00000000 0x014 + n*0x040 control register cr write-only 0x00000000 0x018 + n*0x040 mode register mr read/write 0x00000000 0x01c + n*0x040 status register sr read-only 0x00000000 0x020 + n*0x040 interrupt enable register ier write-only 0x00000000 0x024 + n*0x040 interrupt disable register idr write-only 0x00000000 0x028 + n*0x040 interrupt mask register imr read-only 0x00000000 0x02c + n*0x040 interrupt status register isr read-only 0x00000000
286 32072d?04/2011 at32uc3a3/a4 18.7.3 performance monitor memory map note: 1. the number of performance monitors is device specific. if the device has only one perfor- mance monitor, the channel1 r egisters are not available. please refer to the module configuration section at the end of this chapter for the number of performance monitors on this device. 18.7.4 version register memory map note: 1. the reset values are device specific. please refer to the module configuration section at the end of this chapter. table 18-3. pdca performance monitor registers (1) offset register register name access reset 0x800 performance control register pcontrol read/write 0x00000000 0x804 channel0 read data cycles prdata0 read-only 0x00000000 0x808 channel0 read stall cycles prstall0 read-only 0x00000000 0x80c channel0 read max latency prlat0 read-only 0x00000000 0x810 channel0 write data cycles pwdata0 read-only 0x00000000 0x814 channel0 write stall cycles pwstall0 read-only 0x00000000 0x818 channel0 write max latency pwlat0 read-only 0x00000000 0x81c channel1 read data cycles prdata1 read-only 0x00000000 0x820 channel1 read stall cycles prstall1 read-only 0x00000000 0x824 channel1 read max latency prlat1 read-only 0x00000000 0x828 channel1 write data cycles pwdata1 read-only 0x00000000 0x82c channel1 write stall cycles pwstall1 read-only 0x00000000 0x830 channel1 write max latency pwlat1 read-only 0x00000000 table 18-4. pdca version register memory map offset register register name access reset 0x834 version register version read-only - (1)
287 32072d?04/2011 at32uc3a3/a4 18.7.5 memory address register name: mar access type: read/write offset: 0x000 + n*0x040 reset value: 0x00000000 ? maddr: memory address address of memory buffer. maddr should be programmed to poin t to the start of the memory buffer when configuring the pdca. during transfer, maddr will point to the next memory location to be read/written. 31 30 29 28 27 26 25 24 maddr[31:24] 23 22 21 20 19 18 17 16 maddr[23:16] 15 14 13 12 11 10 9 8 maddr[15:8] 76543210 maddr[7:0]
288 32072d?04/2011 at32uc3a3/a4 18.7.6 peripheral select register name: psr access type: read/write offset: 0x004 + n*0x040 reset value: - ? pid: peripheral identifier the peripheral identifier selects which peripheral should be con nected to the dma channel. writ ing a pid will select both which handshake interface to use, the direction of the transfer and also the address of the receive/transfer holding register for the peripheral. see the module configuration section of pdca for details. the width of the pid field is device specific and dependent on the number of peripheral modules in the device. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 pid
289 32072d?04/2011 at32uc3a3/a4 18.7.7 transfer counter register name: tcr access type: read/write offset: 0x008 + n*0x040 reset value: 0x00000000 ? tcv: transfer counter value number of data items to be transferred by the pdca. tcv must be programmed with the total number of transfers to be made. during transfer, tcv contains the number of remaining transfers to be done. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 tcv[15:8] 76543210 tcv[7:0]
290 32072d?04/2011 at32uc3a3/a4 18.7.8 memory address reload register name: marr access type: read/write offset: 0x00c + n*0x040 reset value: 0x00000000 ? marv: memory address reload value reload value for the mar register. this value will be loaded in to mar when tcr reaches zero if the tcrr register has a non- zero value. 31 30 29 28 27 26 25 24 marv[31:24] 23 22 21 20 19 18 17 16 marv[23:16] 15 14 13 12 11 10 9 8 marv[15:8] 76543210 marv[7:0]
291 32072d?04/2011 at32uc3a3/a4 18.7.9 transfer counter reload register name: tcrr access type: read/write offset: 0x010 + n*0x040 reset value: 0x00000000 ? tcrv: transfer counter reload value reload value for the tcr register. when tcr reaches zero, it will be reloaded with tcrv if tcrv has a positive value. if tcrv is zero, no more transfers will be performed for the chann el. when tcr is reloaded, the tcrr register is cleared. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 tcrv[15:8] 76543210 tcrv[7:0]
292 32072d?04/2011 at32uc3a3/a4 18.7.10 control register name: cr access type: write-only offset: 0x014 + n*0x040 reset value: 0x00000000 ? eclr: transfer error clear writing a zero to this bit has no effect. writing a one to this bit will clear the transfer error bit in the status register (sr.terr). clearing the sr.terr bit will all ow the channel to transmit data. the memory address must first be set to point to a valid location. ? tdis: transfer disable writing a zero to this bit has no effect. writing a one to this bit will disable transfer for the dma channel. ? ten: transfer enable writing a zero to this bit has no effect. writing a one to this bit will enable transfer for the dma channel. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------eclr 76543210 ------tdisten
293 32072d?04/2011 at32uc3a3/a4 18.7.11 mode register name: mr access type: read/write offset: 0x018 + n*0x040 reset value: 0x00000000 ? size: size of transfer 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 ------ size table 18-5. size of transfer size size of transfer 0 byte 1 halfword 2word 3 reserved
294 32072d?04/2011 at32uc3a3/a4 18.7.12 status register name: sr access type: read-only offset: 0x01c + n*0x040 reset value: 0x00000000 ? ten: transfer enabled this bit is cleared when the tdis bit in cr is written to one. this bit is set when the ten bit in cr is written to one. 0: transfer is disabled for the dma channel. 1: transfer is enabled for the dma channel. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------ten
295 32072d?04/2011 at32uc3a3/a4 18.7.13 interrupt enable register name: ier access type: write-only offset: 0x020 + n*0x040 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will set the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - - - - terr trc rcz
296 32072d?04/2011 at32uc3a3/a4 18.7.14 interrupt disable register name: idr access type: write-only offset: 0x024 + n*0x040 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - - - - terr trc rcz
297 32072d?04/2011 at32uc3a3/a4 18.7.15 interrupt mask register name: imr access type: read-only offset: 0x028 + n*0x040 reset value: 0x00000000 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. a bit in this register is cleared when the corresponding bit in idr is written to one. a bit in this register is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - - - - terr trc rcz
298 32072d?04/2011 at32uc3a3/a4 18.7.16 interrupt status register name: isr access type: read-only offset: 0x02c + n*0x040 reset value: 0x00000000 ? terr: transfer error this bit is cleared when no transfer errors ha ve occurred since the last write to cr.eclr. this bit is set when one or more transfer errors has occurred since reset or the last write to cr.eclr. ? trc: transfer complete this bit is cleared when the tcr and/or the tcrr holds a non-zero value. this bit is set when both the tcr and the tcrr are zero. ? rcz: reload counter zero this bit is cleared when the tcrr holds a non-zero value. this bit is set when tcrr is zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - - - - terr trc rcz
299 32072d?04/2011 at32uc3a3/a4 18.7.17 performance control register name: pcontrol access type: read/write offset: 0x800 reset value: 0x00000000 ? mon1ch: performance monitor channel 1 ? mon0ch: performance monitor channel 0 the pdca channel number to monitor with counter n due to performance monitor hardware resour ce sharing, the two performance monitor channels should not be programmed to monitor the same pdca channel. this may result in undefined monitor behavior. ? ch1res: performance channel 1 counter reset writing a zero to this bit has no effect. writing a one to this bit will reset the counter in performance channel 1. this bit always reads as zero. ? ch0res: performance channel 0 counter reset writing a zero to this bit has no effect. writing a one to this bit will reset the counter in performance channel 0. this bit always reads as zero. ? ch1of: performance channel 1 overflow freeze 0: the performance channel registers are reset if data or stall overflows. 1: all performance channel registers are frozen just before data or stall overflows. ? ch1of: performance channel 0 overflow freeze 0: the performance channel registers are reset if data or stall overflows. 1: all performance channel registers are frozen just before data or stall overflows. ? ch1en: performance channel 1 enable 0: performance channel 1 is disabled. 1: performance channel 1 is enabled. ? ch0en: performance channel 0 enable 0: performance channel 0 is disabled. 1: performance channel 0 is enabled. 31 30 29 28 27 26 25 24 -- mon1ch 23 22 21 20 19 18 17 16 -- mon0ch 15 14 13 12 11 10 9 8 ------ch1resch0res 76543210 - - ch1of ch0of - - ch1en ch0en
300 32072d?04/2011 at32uc3a3/a4 18.7.18 performance channel 0 read data cycles name: prdata0 access type: read-only offset: 0x804 reset value: 0x00000000 ? data: data cycles counted since last reset clock cycles are counted us ing the clk_pdca_hsb clock 31 30 29 28 27 26 25 24 data[31:24] 23 22 21 20 19 18 17 16 data[23:16] 15 14 13 12 11 10 9 8 data[15:8] 76543210 data[7:0]
301 32072d?04/2011 at32uc3a3/a4 18.7.19 performance channel 0 read stall cycles name: prstall0 access type: read-only offset: 0x808 reset value: 0x00000000 ? stall: stall cycles counted since last reset clock cycles are counted us ing the clk_pdca_hsb clock 31 30 29 28 27 26 25 24 stall[31:24] 23 22 21 20 19 18 17 16 stall[23:16] 15 14 13 12 11 10 9 8 stall[15:8] 76543210 stall[7:0]
302 32072d?04/2011 at32uc3a3/a4 18.7.20 performance channel 0 read max latency name: prlat0 access type: read/write offset : 0x80c reset value: 0x00000000 ? lat: maximum transfer initiation cycles counted since last reset clock cycles are counted us ing the clk_pdca_hsb clock this counter is saturating. the register is reset only when pcontrol.ch0res is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 lat[15:8] 76543210 lat[7:0]
303 32072d?04/2011 at32uc3a3/a4 18.7.21 performance channel 0 write data cycles name: pwdata0 access type: read-only offset: 0x810 reset value: 0x00000000 ? data: data cycles counted since last reset clock cycles are counted us ing the clk_pdca_hsb clock 31 30 29 28 27 26 25 24 data[31:24] 23 22 21 20 19 18 17 16 data[23:16] 15 14 13 12 11 10 9 8 data[15:8] 76543210 data[7:0]
304 32072d?04/2011 at32uc3a3/a4 18.7.22 performance channel 0 write stall cycles name: pwstall0 access type: read-only offset: 0x814 reset value: 0x00000000 ? stall: stall cycles counted since last reset clock cycles are counted us ing the clk_pdca_hsb clock 31 30 29 28 27 26 25 24 stall[31:24] 23 22 21 20 19 18 17 16 stall[23:16] 15 14 13 12 11 10 9 8 stall[15:8] 76543210 stall[7:0]
305 32072d?04/2011 at32uc3a3/a4 18.7.23 performance channel 0 write max latency name: pwlat0 access type: read/write offset : 0x818 reset value: 0x00000000 ? lat: maximum transfer initiation cycles counted since last reset clock cycles are counted us ing the clk_pdca_hsb clock this counter is saturating. the register is reset only when pcontrol.ch0res is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 lat[15:8] 76543210 lat[7:0]
306 32072d?04/2011 at32uc3a3/a4 18.7.24 performance channel 1 read data cycles name: prdata1 access type: read-only offset: 0x81c reset value: 0x00000000 ? data: data cycles counted since last reset clock cycles are counted us ing the clk_pdca_hsb clock 31 30 29 28 27 26 25 24 data[31:24] 23 22 21 20 19 18 17 16 data[23:16] 15 14 13 12 11 10 9 8 data[15:8] 76543210 data[7:0]
307 32072d?04/2011 at32uc3a3/a4 18.7.25 performance channel 1 read stall cycles name: prstall1 access type: read-only offset: 0x820 reset value: 0x00000000 ? stall: stall cycles counted since last reset clock cycles are counted us ing the clk_pdca_hsb clock 31 30 29 28 27 26 25 24 stall[31:24] 23 22 21 20 19 18 17 16 stall[23:16] 15 14 13 12 11 10 9 8 stall[15:8] 76543210 stall[7:0]
308 32072d?04/2011 at32uc3a3/a4 18.7.26 performance channel 1 read max latency name: platr1 access type: read/write offset : 0x824 reset value: 0x00000000 ? lat: maximum transfer initiation cycles counted since last reset clock cycles are counted us ing the clk_pdca_hsb clock this counter is saturating. the register is reset only when pcontrol.ch1res is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 lat[15:8] 76543210 lat[7:0]
309 32072d?04/2011 at32uc3a3/a4 18.7.27 performance channel 1 write data cycles name: pwdata1 access type: read-only offset: 0x828 reset value: 0x00000000 ? data: data cycles counted since last reset clock cycles are counted us ing the clk_pdca_hsb clock 31 30 29 28 27 26 25 24 data[31:24] 23 22 21 20 19 18 17 16 data[23:16] 15 14 13 12 11 10 9 8 data[15:8] 76543210 data[7:0]
310 32072d?04/2011 at32uc3a3/a4 18.7.28 performance channel 1 write stall cycles name: pwstall1 access type: read-only offset: 0x82c reset value: 0x00000000 ? stall: stall cycles counted since last reset clock cycles are counted us ing the clk_pdca_hsb clock 31 30 29 28 27 26 25 24 stall[31:24] 23 22 21 20 19 18 17 16 stall[23:16] 15 14 13 12 11 10 9 8 stall[15:8] 76543210 stall[7:0]
311 32072d?04/2011 at32uc3a3/a4 18.7.29 performance channel 1 write max latency name: pwlat1 access type: read/write offset : 0x830 reset value: 0x00000000 ? lat: maximum transfer initiation cycles counted since last reset clock cycles are counted us ing the clk_pdca_hsb clock this counter is saturating. the register is reset only when pcontrol.ch1res is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 lat[15:8] 76543210 lat[7:0]
312 32072d?04/2011 at32uc3a3/a4 18.7.30 pdca version register name: version access type: read-only offset: 0x834 reset value: - ? variant: variant number reserved. no functionality associated. ? version: version number version number of the module. no functionality associated. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ---- variant 15 14 13 12 11 10 9 8 - - - - version[11:8] 76543210 version[7:0]
313 32072d?04/2011 at32uc3a3/a4 18.8 module configuration the specific configuration for the pdca in stance is listed in the following tables. 18.8.1 dma handshake signals the table below defines the valid peripheral identifiers (pids). the direction is specified as observed from the memory, so rx means transfers from peripheral to memory and tx means from memory to peripheral. table 18-6. pdca configuration features pdca number of channels 8 table 18-7. register reset values register reset value psrn n version 0x00000110 table 18-8. pdca handshake signals pid value direction peripheral instance peripheral register 0 rx adc cdrx 1 rx ssc rhr 2 rx usart0 rhr 3 rx usart1 rhr 4 rx usart2 rhr 5 rx usart3 rhr 6 rx twim0 rhr 7 rx twim1 rhr 8 rx twis0 rhr 9 rx twis1 rhr 10 rx spi0 rdr 11 rx spi1 rdr 12 tx ssc thr 13 tx usart0 thr 14 tx usart1 thr 15 tx usart2 thr 16 tx usart3 thr 17 tx twim0 thr 18 tx twim1 thr 19 tx twis0 thr 20 tx twis1 thr
314 32072d?04/2011 at32uc3a3/a4 21 tx spi0 tdr 22 tx spi1 tdr 23 tx abdac sdr table 18-8. pdca handshake signals pid value direction peripheral instance peripheral register
315 32072d?04/2011 at32uc3a3/a4 19. dma controller (dmaca) rev: 2.0.6.6 19.1 features ? 2 hsb master interfaces ? 4 channels ? software and hardware handshaking interfaces ? 8 hardware handshaking interfaces ? memory/non-memory periph erals to memory/non-mem ory peripherals transfer ? single-block dma transfer ? multi-block dma transfer ? linked lists ? auto-reloading ? contiguous blocks ? dma controller is always the flow controller ? additional features ? scatter and gather operations ? channel locking ? bus locking ? fifo mode ? pseudo fly-by operation 19.2 overview the dma controller (dmaca) is an hsb-central dma controller core that transfers data from a source peripheral to a destination peripheral over one or more system bus. one channel is required for each source/destination pair. in the most basic configuration, the dmaca has one master interface and one channel. the master interface reads the data from a source and writes it to a destination. two system bus transfers are required for each dma data transfer. this is also known as a dual-access transfer. the dmaca is programmed via the hsb slave interface.
316 32072d?04/2011 at32uc3a3/a4 19.3 block diagram figure 19-1. dma controller (dmaca) block diagram 19.4 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 19.4.1 i/o lines the pins used for interfacing the compliant exte rnal devices may be multiplexed with gpio lines. the user must first program the gpio controlle r to assign the dmaca pins to their peripheral functions. 19.4.2 power management to prevent bus errors the dmaca operation must be terminated before entering sleep mode. 19.4.3 clocks the clk_dmaca to the dmaca is generated by the power manager (pm). before using the dmaca, the user must ensure that the dmaca clock is enabled in the power manager. 19.4.4 interrupts the dmaca interface has an interrupt line connect ed to the interrupt controller. handling the dmaca interrupt requires programming the inte rrupt controller before configuring the dmaca. 19.4.5 peripherals both the source peripheral and the destination peripheral must be set up correctly prior to the dma transfer. hsb slave i/f hsb master i/f cfg interrupt generator fifo channel 0 src fsm dst fsm channel 1 dma controller irq_dma hsb slave hsb master
317 32072d?04/2011 at32uc3a3/a4 19.5 functional description 19.5.1 basic definitions source peripheral: device on a system bus layer from where the dmaca reads data, which is then stored in the channel fifo. the source peripheral teams up with a destination peripheral to form a channel. destination peripheral: device to which the dmaca writes the stored data from the fifo (pre- viously read from the source peripheral). memory: source or destination that is always ?ready? for a dma transfer and does not require a handshaking interface to interact with the dmaca. a peripheral should be assigned as memory only if it does not insert more than 16 wait states. if more than 16 wait states are required, then the peripheral should use a handshaking interface (the default if the peripheral is not pro- grammed to be memory) in order to signal when it is ready to accept or supply data. channel: read/write datapath between a source peripheral on one configured system bus layer and a destination peripheral on the same or different system bus layer that occurs through the channel fifo. if the source peripheral is not memory, then a source handshaking interface is assigned to the channel. if the destination pe ripheral is not memory, then a destination hand- shaking interface is assigned to the channel. so urce and destination handshaking interfaces can be assigned dynamically by programming the channel registers. master interface: dmaca is a master on the hsb bus reading data from the source and writing it to the destination over the hsb bus. slave interface: the hsb interface over which the dmaca is programmed. the slave interface in practice could be on the same layer as any of the master interfaces or on a separate layer. handshaking interface: a set of signal registers that conform to a protocol and handshake between the dmaca and source or destination peripheral to control the transfer of a single or burst transaction between them. this interface is used to request, acknowledge, and control a dmaca transaction. a channel can receive a request through one of three types of handshaking interface: hardware, software, or peripheral interrupt. hardware handshaking interface: uses hardware signals to control the transfer of a single or burst transaction between the dmaca and the source or destination peripheral. software handshaking interface: uses software registers to control the transfer of a single or burst transaction between the dmaca and the so urce or destination peripheral. no special dmaca handshaking signals are needed on the i/o of the peripheral. this mode is useful for interfacing an existing peripheral to the dmac a without modifying it. peripheral interrupt handshaking interface: a simple use of the hardware handshaking inter- face. in this mode, the interrupt line from the peripheral is tied to the dma_req input of the hardware handshaking interface. other interface signals are ignored. flow controller: the device (either the dmaca or sour ce/destination peripheral) that deter- mines the length of and terminates a dma block transfer. if the length of a block is known before enabling the channel, then the dmaca should be programmed as the flow controller. if the length of a block is not known prior to enabling the channel, the source or destination peripheral needs to terminate a block transfer. in this mode, the peripheral is the flow controller. flow control mode (cfgx.fcmode): special mode that only applies when the destination peripheral is the flow controller. it controls the pre-fetching of data from the source peripheral.
318 32072d?04/2011 at32uc3a3/a4 transfer hierarchy: figure 19-2 on page 318 illustrates the hierarchy between dmaca trans- fers, block transfers, transactions (single or burst), and system bus transfers (single or burst) for non-memory peripherals. figure 19-3 on page 318 shows the transfer hierarchy for memory. figure 19-2. dmaca transfer hierarchy for non-memory peripheral figure 19-3. dmaca transfer hierarchy for memory block: a block of dmaca data. the amount of data (block length) is determined by the flow controller. for transfers between the dmaca and memory, a block is broken directly into a sequence of system bus bursts and single transfers. for transfers between the dmaca and a non-memory peripheral, a block is broken into a sequence of dmaca transactions (single and bursts). these are in turn broken into a sequence of system bus transfers. transaction: a basic unit of a dmaca transfer as dete rmined by either the hardware or soft- ware handshaking interface. a tr ansaction is only relevant for transfers between the dmaca and a source or destination peripheral if the source or destination peripheral is a non-memory device. there are two types of transactions: single and burst. dmac transfer dma transfer level block block block block transfer level burst transaction burst transaction burst transaction single transaction dma transaction level burst transfer system bus burst transfer system bus burst transfer system bus single transfer system bus system bus transfer level single transfer system bus dmac transfer dma transfer level block block block block transfer level burst transfer system bus burst transfer system bus burst transfer system bus single transfer system bus system bus transfer level
319 32072d?04/2011 at32uc3a3/a4 ? single transaction: the length of a single transaction is always 1 and is converted to a single system bus transfer. ? burst transaction: the length of a burst transaction is programmed into the dmaca. the burst transaction is converted into a sequence of system bus bursts and single transfers. dmaca executes each burst transfer by performing incremental bursts that are no longer than the maximum system bus burst size set. the burst transaction length is under program control and normally bears some relationship to the fifo sizes in the dmaca and in the source and destination peripherals. dma transfer: software controls the number of blocks in a dmaca transfer. once the dma transfer has completed, then hardware within the dmaca disables the channel and can gener- ate an interrupt to signal the completion of the dma transfer. you can then re-program the channel for a new dma transfer. single-block dma transfer: consists of a single block. multi-block dma transfer: a dma transfer may consist of mu ltiple dmaca blocks. multi-block dma transfers are supported through block chaining (linked list pointers), auto-reloading of channel registers, and contiguous blocks. the source and destination can independently select which method to use. ? linked lists (block chaining) ? a linked list pointer (llp) points to the location in system memory where the next linked list item (lli) exists. the lli is a set of registers that describe the next block (block descriptor) and an llp register. the dmaca fetches the lli at the beginning of every block when block chaining is enabled. ? auto-reloading ? the dmaca automatically reloads the channel registers at the end of each block to the value when the channel was first enabled. ? contiguous blocks ? where the address between successive blocks is selected to be a continuation from the end of the previous block. scatter: relevant to destination transfers within a block. the destination system bus address is incremented or decremented by a programmed amount -the scatter increment- when a scatter boundary is reached. the destination system bu s address is incremented or decremented by the value stored in the destination scatter increment (dsrx.dsi) field, multiplied by the number of bytes in a single hsb transfer to the destination (decoded value of ctlx.dst_tr_width)/8. the number of destination transfers between successive scatter boundaries is programmed into the destination scatter count (dsc ) field of the dsrx register. scatter is enabled by writing a ?1? to the ctlx.dst_scatter_en bit. the ctlx.dinc field determines if the address is incremented, decremented or remains fixed when a scatter bound- ary is reached. if the ctlx.dinc field indi cates a fixed-address control throughout a dma transfer, then the ctlx.dst_scatter_en bit is ignored, and the scatter feature is automati- cally disabled. gather: relevant to source transfers within a block. the source system bus address is incre- mented or decremented by a programmed amount when a gather boundary is reached. the number of system bus transfers between successive gather boundaries is programmed into the source gather count (sgrx.sgc) field. the source address is incremented or decremented by the value stored in the source gather increment (sgrx.sgi) field multiplied by the number of bytes in a single hsb transfer from the source -(decoded value of ctlx.src_tr_width)/8 - when a gather boundary is reached.
320 32072d?04/2011 at32uc3a3/a4 gather is enabled by writing a ?1? to the ctlx.src_gather_en bit. the ctlx.sinc field determines if the address is incremented, decremented or remains fixed when a gather bound- ary is reached. if the ctlx.sinc field indicates a fixed-address control throughout a dma transfer, then the ctlx.src_gather_en bit is ignored and the gather feature is automatically disabled. note: for multi-block transfers, the counters that keep track of the number of transfer left to reach a gather/scatter boundary are re-initialized to the source gather count (sgrx.sgc) and destination scatter count (dsrx.dsc), respecti vely, at the start of each block transfer. figure 19-4. destination sc atter transfer d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0 0 x 080 system memory a0 + 0x218 a0 + 0x210 a0 + 0x208 a0 + 0x200 a0 + 0x118 a0 + 0x110 a0 + 0x108 a0 + 0x100 scatter increment a0 + 0x018 a0 + 0x010 a0 + 0x008 a0 scatter increment 0 x 080 scatter boundary a0 + 0x220 scatter boundary a0 + 0x120 scatter boundary a0 + 0x020 data stream d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d11 d8 d7 d4 d3 d0 dsr.dsi * 8 = 0x80 (scatter increment in bytes) ctlx.dst_tr_width = 3'b011 (64bit/8 = 8 bytes) dsr.dsi = 16 dsr.dsc = 4
321 32072d?04/2011 at32uc3a3/a4 figure 19-5. source gather transfer channel locking: software can program a channel to keep the hsb master interface by locking the arbitration for the master bus interface for the duration of a dma transfer, block, or transac- tion (single or burst). bus locking: software can program a channel to maintain control of the system bus bus by asserting hlock for the duration of a dma transfer, block, or transaction (single or burst). chan- nel locking is asserted for the duration of bus locking at a minimum. fifo mode: special mode to improve bandwidth. when enabled, the channel waits until the fifo is less than half full to fetch the data from the source peripheral and waits until the fifo is greater than or equal to half full to send data to the destination peripheral. thus, the channel can transfer the data using system bus bursts, eliminating the need to arbitrate for the hsb master interface for each single system bus transfer. when this mode is not enabled, the channel only waits until the fifo can transmit/accept a single system bus transfer before requesting the master bus interface. pseudo fly-by operation: typically, it takes two system bu s cycles to complete a transfer, one for reading the source and one for writing to the destination. however, when the source and des- tination peripherals of a dma transfer are on differ ent system bus layers, it is possible for the dmaca to fetch data from the source and store it in the channel fifo at the same time as the dmaca extracts data from the channel fifo and writes it to the destination peripheral. this activity is known as pseudo fly-by operation . for this to occur, the master interface for both source and destination layers must win arbitration of their hsb layer. similarly, the source and destination peripherals must win ownership of their respective master interfaces. d11 d10 d9 d8 system memory a0 + 0x034 a0 + 0x030 a0 + 0x02c a0 + 0x028 d11 d8 d7 d4 a0 + 0x020 a0 + 0x01c a0 + 0x018 a0 + 0x014 d7 d6 d5 d4 d3 d2 d1 d0 a0 + 0x00c a0 + 0x008 a0 + 0x004 a0 d3 d0 gather boundary a0 + 0x24 gather increment = 4 data stream d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 gather boundary a0 + 0x38 gather increment = 4 gather boundary a0 + 0x10 gather increment = 4 sgr.sgi * 4 = 0x4 (gather increment in bytes) ctlx.src_tr_width = 3'b010 (32bit/8 = 4 bytes) sgr.sgi = 1 sgr.sgc = 4
322 32072d?04/2011 at32uc3a3/a4 19.6 arbitration for h sb master interface each dmaca channel has two request lines that request ownership of a particular master bus interface: channel source and channel destination request lines. source and destination arbitrate separately fo r the bus. once a source/destination state machine gains ownership of the master bus inte rface and the master bus interface has owner- ship of the hsb bus, then hsb transfers can proceed between the peripheral and the dmaca. an arbitration scheme decides which of t he request lines (2 * dmah_num_channels) is granted the particular master bus interface. each channel has a programmable priority. a request for the master bus interface can be made at any time, but is granted only after the cur- rent hsb transfer (burst or single) has completed. therefore, if the master interface is transferring data for a lower priority channel and a higher priority channel requests service, then the master interface will complete the current burst for the lower priority channel before switch- ing to transfer data for the higher priority channel. if only one request line is active at the highest priority level, then the request with the highest pri- ority wins ownership of the hsb master bus interface; it is not necessary for the priority levels to be unique. if more than one request is active at the highest requesting priority, then these competing requests proceed to a second tier of arbitration: if equal priority requests occur, then the lower-numbered channel is granted. in other words, if a peripheral request attached to channel 7 and a peripheral request attached to channel 8 have the same priority, then the peripheral attached to channel 7 is granted first. 19.7 memory peripherals figure 19-3 on page 318 shows the dma transfer hierarchy of the dmaca for a memory periph- eral. there is no handshaking interface with the dmaca, and therefore the memory peripheral can never be a flow controller. once the channel is enabled, the transfer proceeds immediately without waiting for a transaction request. the alternative to not having a transaction-level hand- shaking interface is to allow the dmaca to attempt system bus transfers to the peripheral once the channel is enabled. if the peripheral slave cannot accept these system bus transfers, it inserts wait states onto the bus until it is ready; it is not recommended that more than 16 wait states be inserted onto the bus. by using the handshaking interface, the peripheral can signal to the dmaca that it is ready to transmit/receive data, and then the dmaca can access the peripheral without the peripheral inserting wait states onto the bus. 19.8 handshaking interface handshaking interfaces are used at the transactio n level to control the flow of single or burst transactions. the operation of the handshaking interface is different and depends on whether the peripheral or the dmaca is the flow controller. the peripheral uses the handshaking interface to indi cate to the dmaca that it is ready to trans- fer/accept data over the system bus. a non-memory peripheral can request a dma transfer through the dmaca using one of two handshaking interfaces: ? hardware handshaking ? software handshaking
323 32072d?04/2011 at32uc3a3/a4 software selects between the hardware or software handshaking interface on a per-channel basis. software handshaking is accomplished through memory-mapped registers, while hard- ware handshaking is accomplished usin g a dedicated handshaking interface. 19.8.1 software handshaking when the slave peripheral requires the dmaca to perform a dma transaction, it communicates this request by sending an interrupt to the cpu or interrupt controller. the interrupt service routine then uses the software registers to initiate and control a dma trans- action. these software registers are used to implement the software handshaking interface. the hs_sel_src/hs_sel_dst bit in the cfgx channel configuration register must be set to enable software handshaking. when the peripheral is not the flow controller, then the last transaction registers lstsrcreg and lstdstreg are not used, and the values in these registers are ignored. 19.8.1.1 burst transactions writing a 1 to the reqsrcreg[x]/reqdstreg[x] register is always interpreted as a burst transac- tion request, where x is the channel number. however, in order for a burst transaction request to start, software must write a 1 to the sglreqsrcreg[x]/sglreqdstreg[x] register. you can write a 1 to the sglreqsrcreg[ x ]/sglreqdstreg[ x ] and reqsrcreg[ x ]/reqdstreg[ x ] registers in any order, but both registers must be asserted in order to initiate a burst transaction. upon completion of the burst transaction, the hardware clears the sglreqsrcreg[ x ]/sglreqd- streg[ x ] and reqsrcreg[ x ]/reqdstreg[ x ] registers. 19.8.1.2 single transactions writing a 1 to the sg lreqsrcreg/sglreqdstreg initiates a single transaction. upon completion of the single transaction, both the sglreq srcreg/sglreqdstreg and reqsrcreg/reqdstreg bits are cleared by hardware. therefore, writ ing a 1 to the reqsrcreg/reqdstreg is ignored while a single transaction has been initiated, and the requested burst transaction is not serviced. again, writing a 1 to the reqsrcreg/reqdstre g register is always a burst transaction request. however, in order for a burst transaction request to start, the corresponding channel bit in the sglreqsrcreg/sglreqdstreg must be asserted. therefore, to ensure that a burst transaction is serviced, you must write a 1 to the reqsrcr eg/reqdstreg before writing a 1 to the sglreqsr- creg/sglreqdstreg register. software can poll the relevant channel bit in the sglreqsrcreg/ sglreqdstreg and reqsr- creg/reqdstreg registers. when both are 0, then either the requested burst or single transaction has completed. alternatively, the intsrctran or intdsttran interrupts can be enabled and unmasked in order to generate an interrupt when the requested source or destination trans- action has completed. note: the transaction-complete interrupts are trigger ed when both single and burst transactions are complete. the same transaction-complete interrupt is used for both single and burst transactions. 19.8.2 hardware handshaking there are 8 hardware handshaking interfaces between the dmaca and peripherals. refer to the module configuration chapter for the device-specific mapping of these interfaces.
324 32072d?04/2011 at32uc3a3/a4 19.8.2.1 external dma request definition when an external slave peripheral requires the dmaca to perform dma transactions, it commu- nicates its request by asserting the external ndma reqx signal. this signal is resynchronized to ensure a proper functionality (see ?external dma request timing? on page 324 ). the external ndmareqx signal should be assert ed when the source threshold level is reached. after resynchronization, the rising edge of dma_ req starts the transfer. an external dmaackx acknowledge signal is also provided to indica te when the dma transfer has completed. the peripheral should de-assert the dma requ est signal when dmaackx is asserted. the external ndmareqx signal must be de-ass erted after the last transfer and re-asserted again before a new transaction starts. for a source fifo, an active edge should be triggered on ndmareqx when the source fifo exceeds a watermark level. for a destination fifo, an active edge should be triggered on ndmareqx when the destination fifo drops below the watermark level. the source transaction length, ctlx.src_msize, and destination transaction length, ctlx.dest_msize, must be set according to watermark levels on the source/destination peripherals. figure 19-6. external dma request timing 19.9 dmaca transfer types a dma transfer may consist of single or multi-block transfers. on successive blocks of a multi- block transfer, the sarx/darx register in the dm aca is reprogrammed using either of the fol- lowing methods: ? block chaining using linked lists ? auto-reloading ? contiguous address between blocks on successive blocks of a multi-block transfer, the ctlx register in the dmaca is re-pro- grammed using either of the following methods: ? block chaining using linked lists ? auto-reloading when block chaining, using linked lists is the multi-block method of choice, and on successive blocks, the llpx register in the dmaca is re-programmed using the following method: ? block chaining using linked lists dma transfers dma transfers hclk ndmareqx dma_req dma_ack dma transfers dma transaction
325 32072d?04/2011 at32uc3a3/a4 a block descriptor (lli) consists of following r egisters, sarx, darx, llpx, ctl. these regis- ters, along with the cfgx register, are used by the dmaca to set up and describe the block transfer. 19.9.1 multi-block transfers 19.9.1.1 block chaining using linked lists in this case, the dmaca re-programs the channel registers prior to the start of each block by fetching the block descriptor for that block from system memory. this is known as an lli update. dmaca block chaining is supported by using a linked list pointer register (llpx) that stores the address in memory of the next linked list item. each lli (block descriptor) contains the corre- sponding block descriptor (sarx, darx, llpx, ctlx). to set up block chaining, a sequence of linked lists must be programmed in memory. the sarx, darx, llpx and ctlx registers are fetched from system memory on an lli update. the updated contents of the ctlx register are written back to memory on block completion. fig- ure 19-7 on page 325 shows how to use chained linked lists in memory to define multi-block transfers using block chaining. the linked list multi-block transfers is initiated by programming llpx with llpx(0) (lli(0) base address) and ctlx with ctlx.llp_s_en and ctlx.llp_d_en. figure 19-7. multi-block transfer using linked lists system memory sarx darx llpx(1) ctlx[31..0] ctlx[63..32] sarx darx llpx(2) ctlx[31..0] ctlx[63..32] llpx(0) llpx(2) llpx(1) lli(0) lli(1)
326 32072d?04/2011 at32uc3a3/a4 19.9.1.2 auto-reloading of channel registers during auto-reloading, the channel registers are reloaded with their initial values at the comple- tion of each block and the new values used for the new block. depending on the row number in table 19-1 on page 326 , some or all of the sarx, darx and ctlx channel registers are reloaded from their initial value at the start of a block transfer. 19.9.1.3 contiguous address between blocks in this case, the address between successive bloc ks is selected to be a continuation from the end of the previous block. enabling the source or destination address to be contiguous between table 19-1. programming of transfer types and channel register update method (dmaca state machine table) transfer type llp. loc = 0 llp_s_en ( ctlx) reload _sr ( cfgx) llp_d_en ( ctlx) reload_ ds ( cfgx) ctlx, llpx update method sarx update method darx update method write back 1) single block or last transfer of multi-block ye s 0 0 0 0 none, user reprograms none (single) none (single) no 2) auto reload multi-block transfer with contiguous sar ye s 0 0 0 1 ctlx,llpx are reloaded from initial values. contiguous auto- reload no 3) auto reload multi-block transfer with contiguous dar ye s 0 1 0 0 ctlx,llpx are reloaded from initial values. auto-reload con- tiguous no 4) auto reload multi-block transfer ye s 0 1 0 1 ctlx,llpx are reloaded from initial values. auto-reload auto- reload no 5) single block or last transfer of multi-block no 0 0 0 0 none, user reprograms none (single) none (single) ye s 6) linked list multi-block transfer with contiguous sar no 0 0 1 0 ctlx,llpx loaded from next linked list item contiguous linked list ye s 7) linked list multi-block transfer with auto-reload sar no 0 1 1 0 ctlx,llpx loaded from next linked list item auto-reload linked list ye s 8) linked list multi-block transfer with contiguous dar no 1 0 0 0 ctlx,llpx loaded from next linked list item linked list con- tiguous ye s 9) linked list multi-block transfer with auto-reload dar no 1 0 0 1 ctlx,llpx loaded from next linked list item linked list auto- reload ye s 10) linked list multi-block transfer no 1 0 1 0 ctlx,llpx loaded from next linked list item linked list linked list ye s
327 32072d?04/2011 at32uc3a3/a4 blocks is a function of ctlx.llp_s_en, cfgx.reloa d_sr, ctlx.llp_d_en, and cfgx.reload_ds registers (see figure 19-1 on page 316 ). note: both sarx and darx updates cannot be se lected to be contiguous. if this functionality is required, the size of the block tr ansfer (ctlx.block_ts) must be increased. if this is at the max- imum value, use row 10 of table 19-1 on page 326 and setup the lli.sarx address of the block descriptor to be equal to the end sarx address of the previous block. similarly, setup the lli.darx address of the block descriptor to be equal to the end darx address of the previous block. 19.9.1.4 suspension of transfers between blocks at the end of every block transfer, an end of block interrupt is asserted if: ? interrupts are enabled, ctlx.int_en = 1 ? the channel block interrupt is unmasked, maskblock[n] = 0, where n is the channel number. note: the block complete interrupt is generated at the completion of the block transfer to the destination. for rows 6, 8, and 10 of table 19-1 on page 326 , the dma transfer does not stall between block transfers. for example, at the end of block n, the dmaca automatically proceeds to block n + 1. for rows 2, 3, 4, 7, and 9 of table 19-1 on page 326 (sarx and/or darx auto-reloaded between block transfers), the dma transfer automatically stalls after the end of block. interrupt is asserted if the end of block interrupt is enabled and unmasked. the dmaca does not proceed to the next block transfer until a write to the block interrupt clear register, clearblock[n], is performed by software. this clears the channel block complete interrupt. for rows 2, 3, 4, 7, and 9 of table 19-1 on page 326 (sarx and/or darx auto-reloaded between block transfers), the dma transfer does not stall if either: ? interrupts are disabled, ctlx.int_en = 0, or ? the channel block interrupt is masked, maskblock[n] = 1, where n is the channel number. channel suspension between blocks is used to ensu re that the end of block isr (interrupt ser- vice routine) of the next-to-last block is serviced before the start of the final block commences. this ensures that the isr has cleared the cfgx.reload_sr and/or cfgx.reload_ds bits before completion of the final block. the reload bits cfgx.reload_sr and/or cfgx.reload_ds should be cleared in the ?end of block isr? for the next-to-last block transfer. 19.9.2 ending multi-block transfers all multi-block transfers must end as shown in either row 1 or row 5 of table 19-1 on page 326 . at the end of every block transfer, the dmaca samples the row number, and if the dmaca is in row 1 or row 5 state, then the previous block transferred was the last block and the dma trans- fer is terminated. note: row 1 and row 5 are used for single block transfers or terminating multiblock transfers. ending in row 5 state enables status fetch for the last block. ending in row 1 state disables status fetch for the last block. for rows 2,3 and 4 of table 19-1 on page 326 , (llpx = 0 and cfgx.reload_sr and/or cfgx.reload_ds is set), multi-block dma transfers continue until both the cfgx.reload_sr and cfgx.reload_ds registers are cleared by software. they should be
328 32072d?04/2011 at32uc3a3/a4 programmed to zero in the end of block interrupt service routine that services the next-to-last block transfer. this puts the dmaca into row 1 state. for rows 6, 8, and 10 (both cfgx.reload_sr and cfgx.reload_ds cleared) the user must setup the last block descriptor in memory such that both lli.ctlx.llp_s_en and lli.ctlx.llp_d_en are zero. if the lli.llpx register of the last block descriptor in memory is non-zero, then the dma transfer is terminated in row 5. if the lli.llpx register of the last block descriptor in memory is zero, then the dma transfer is terminated in row 1. for rows 7 and 9, the end-of-block interrupt serv ice routine that services the next-to-last block transfer should clear the cfgx.reload_sr and cfgx.reload_ds reload bits. the last block descriptor in memory should be set up so that both the lli.ctlx.llp_s_en and lli.ctlx.llp_d_en are zero. if the lli.llpx register of the last block descriptor in memory is non-zero, then the dma transfer is terminated in row 5. if the lli.llpx register of the last block descriptor in memory is zero, then the dma transfer is terminated in row 1. note: the only allowed transitions between the rows of table 19-1 on page 326 are from any row into row 1 or row 5. as already stated, a transition in to row 1 or row 5 is used to terminate the dma transfer. all other transitions between rows are not allowed. software must ensure that illegal tran- sitions between rows do not occur between blocks of a multi-block transfer. for example, if block n is in row 10 then the only allowed rows for block n + 1 are rows 10, 5 or 1. 19.10 programming a channel three registers, the llpx, the ctlx and cfgx, need to be programmed to set up whether single or multi-block transfers take place, and which type of multi-block transfer is used. the different transfer types are shown in table 19-1 on page 326 . the ?update method? column indicates where the values of sarx, darx, ctlx, and llpx are obtained for the next block transfer when multi-block dmaca transfers are enabled. note: in table 19-1 on page 326 , all other combinations of llpx.loc = 0, ctlx.llp_s_en, cfgx.reload_sr, ctlx.llp_d_en, and cfgx.r eload_ds are illegal, and causes indeter- minate or erroneous behavior. 19.10.1 programming examples 19.10.1.1 single-block transfer (row 1) row 5 in table 19-1 on page 326 is also a single block transfer. 1. read the channel enable register to choose a free (disabled) channel. 2. clear any pending interrupts on the channel from the previous dma transfer by writing to the interrupt clear registers: cleartfr, clearblock, clearsrctran, cleardsttran, clearerr. reading the interrupt raw status and interrupt status registers confirms that all interrupts have been cleared. 3. program the following channel registers: a. write the starting source address in the sarx register for channel x. b. write the starting destination address in the darx register for channel x. c. program ctlx and cfgx according to row 1 as shown in table 19-1 on page 326 . program the llpx register with ?0?. d. write the control information for the dma transfer in the ctlx register for channel x. for example, in the register, you can program the following: ? i. set up the transfer type (memory or non-memory peripheral for source and destination) and flow control device by programming the tt_fc of the ctlx register.
329 32072d?04/2011 at32uc3a3/a4 ? ii. set up the transfer characteristics, such as: ? transfer width for the source in the src_tr_width field. ? transfer width for the destination in the dst_tr_width field. ? source master layer in the sms field where source resides. ? destination master layer in the dms field where destination resides. ? incrementing/decrementing or fixed address for source in sinc field. ? incrementing/decrementing or fixed address for destination in dinc field. e. write the channel configuration information into the cfgx register for channel x. ? i. designate the handshaking interface type (hardware or software) for the source and destination peripherals. this is not required for memory. this step requires programming the hs_sel_src/hs_sel_dst bits, respectively. writing a ?0? activates the hardware handshaking interface to handle source/destination requests. writing a ?1? activates the software handshaking interface to handle source/destination requests. ? ii. if the hardware handshaking interface is activated for the source or destination peripheral, assign a handshaking interface to the source and destination peripheral. this requires programming the src_per and dest_per bits, respectively. 4. after the dmaca selected channel has been programmed, enable the channel by writ- ing a ?1? to the chenreg.ch_en bit. make sure that bit 0 of the dmacfgreg register is enabled. 5. source and destination request single and burst dma transactions to transfer the block of data (assuming non-memory peripherals). the dmaca acknowledges at the com- pletion of every transaction (burst and single) in the block and carry out the block transfer. 6. once the transfer completes, hardware sets the interrupts and disables the channel. at this time you can either respond to the block complete or transfer complete interrupts, or poll for the channel enable (chenreg.ch_en) bit until it is cleared by hardware, to detect when the transfer is complete. 19.10.1.2 multi-block transfer with linked list for source and linked list for destination (row 10) 1. read the channel enable register to choose a free (disabled) channel. 2. set up the chain of linked list items (otherwise known as block descriptors) in memory. write the control information in the lli.ctlx register location of the block descriptor for each lli in memory (see figure 19-7 on page 325 ) for channel x. for example, in the register, you can program the following: a. set up the transfer type (memory or non-memory peripheral for source and desti- nation) and flow control device by programming the tt_fc of the ctlx register. b. set up the transfer characteristics, such as: ? i. transfer width for the source in the src_tr_width field. ? ii. transfer width for the destination in the dst_tr_width field. ? iii. source master layer in th e sms field where source resides. ? iv. destination master layer in the dms field where destination resides. ? v. incrementing/decrementing or fixed address for source in sinc field. ? vi. incrementing/decrementing or fixed address for destination dinc field. 3. write the channel configuration information into the cfgx register for channel x.
330 32072d?04/2011 at32uc3a3/a4 a. designate the handshaking interface type (hardware or software) for the source and destination peripherals. this is not required for memory. this step requires pro- gramming the hs_sel_src/hs_sel_dst bits, respectively. writing a ?0? activates the hardware handshaking interface to handle source/destination requests for the specific channel. writing a ?1? activates the software handshaking interface to handle source/destination requests. b. if the hardware handshaking interface is activated for the source or destination peripheral, assign the handshaking interface to the source and destination periph- eral. this requires programming the src_per and dest_per bits, respectively. 4. make sure that the lli.ctlx register locations of all lli entries in memory (except the last) are set as shown in row 10 of table 19-1 on page 326 . the lli.ctlx register of the last linked list item must be set as described in row 1 or row 5 of table 19-1 on page 326 . figure 19-9 on page 332 shows a linked list example with two list items. 5. make sure that the lli.llpx register locations of all lli entries in memory (except the last) are non-zero and point to the base address of the next linked list item. 6. make sure that the lli.sarx/lli.darx register locations of all lli entries in memory point to the start source/destination block address preceding that lli fetch. 7. make sure that the lli.ctlx.done field of the lli.ctlx register locations of all lli entries in memory are cleared. 8. clear any pending interrupts on the channel from the previous dma transfer by writing to the interrupt clear registers: cleartfr, clearblock, clearsrctran, cleardsttran, clearerr. reading the interrupt raw status and interrupt status registers confirms that all interrupts have been cleared. 9. program the ctlx, cfgx registers according to row 10 as shown in table 19-1 on page 326 . 10. program the llpx register with llpx(0), the pointer to the first linked list item. 11. finally, enable the channel by writing a ?1? to the chenreg.ch_en bit. the transfer is performed. 12. the dmaca fetches the first lli from the location pointed to by llpx(0). note: the lli.sarx, lli. darx, lli.llpx and lli.ct lx registers are fetched. the dmaca automati- cally reprograms the sarx, darx, llpx and ctlx channel registers from the llpx(0). 13. source and destination request single and burst dma transactions to transfer the block of data (assuming non-memory peripheral). the dmaca acknowledges at the comple- tion of every transaction (burst and single) in the block and carry out the block transfer. note: table 19-1 on page 326 14. the dmaca does not wait for the block interrupt to be cleared, but continues fetching the next lli from the memory location pointed to by current llpx register and automat- ically reprograms the sarx, darx, llpx and ctlx channel registers. the dma transfer continues until the dmaca determines that the ctlx and llpx registers at the end of a block transfer match that described in row 1 or row 5 of table 19-1 on page 326 . the dmaca then knows that the previous block transferred was the last block in the dma transfer. the dma transfer might look like that shown in figure 19-8 on page 331 .
331 32072d?04/2011 at32uc3a3/a4 figure 19-8. multi-block with linked list address for source and destination if the user needs to execute a dma transfer wh ere the source and destination address are con- tiguous but the amount of data to be transferred is greater than the maximum block size ctlx.block_ts, then this can be achieved usin g the type of multi-block transfer as shown in figure 19-9 on page 332 . sar(2) sar(1) sar(0) dar(2) dar(1) dar(0) block 2 block 1 block 0 block 0 block 1 block 2 address of source layer address of destination layer source blocks destination blocks
332 32072d?04/2011 at32uc3a3/a4 figure 19-9. multi-block with linked address for source and destination blocks are contiguous the dma transfer flow is shown in figure 19-11 on page 335 . sar(2) sar(1) sar(0) dar(2) dar(1) dar(0) block 2 block 1 block 0 block 0 block 1 block 2 address of source layer address of destination layer source blocks destination blocks sar(3) block 2 dar(3) block 2
333 32072d?04/2011 at32uc3a3/a4 figure 19-10. dma transfer flow for source and destination linked list address 19.10.1.3 multi-block transfer with source address auto-reloaded and destination address auto-reloaded (row 4) 1. read the channel enable register to choose an available (disabled) channel. 2. clear any pending interrupts on the channel from the previous dma transfer by writing to the interrupt clear registers: cleartfr, clearblock, clearsrctran, cleardsttran, clearerr. reading the interrupt raw status and interrupt status registers confirms that all interrupts have been cleared. 3. program the following channel registers: channel enabled by software lli fetch hardware reprograms sarx, darx, ctlx, llpx dmac block transfer source/destination status fetch is dmac in row1 of dmac state machine table? channel disabled by hardware block complete interrupt generated here dmac transfer complete interrupt generated here yes no
334 32072d?04/2011 at32uc3a3/a4 a. write the starting source address in the sarx register for channel x. b. write the starting destination address in the darx register for channel x. c. program ctlx and cfgx according to row 4 as shown in table 19-1 on page 326 . program the llpx register with ?0?. d. write the control information for the dma transfer in the ctlx register for channel x. for example, in the register, you can program the following: ? i. set up the transfer type (memory or non-memory peripheral for source and destination) and flow control device by programming the tt_fc of the ctlx register. ? ii. set up the transfer characteristics, such as: ? transfer width for the source in the src_tr_width field. ? transfer width for the destination in the dst_tr_width field. ? source master layer in the sms field where source resides. ? destination master layer in the dms field where destination resides. ? incrementing/decrementing or fixed address for source in sinc field. ? incrementing/decrementing or fixed address for destination in dinc field. e. write the channel configuration information into the cfgx register for channel x. ensure that the reload bits, cfgx. reload_sr and cfgx.reload_ds are enabled. ? i. designate the handshaking interface type (hardware or software) for the source and destination peripherals. this is not required for memory. this step requires programming the hs_sel_src/hs_sel_dst bits, respectively. writing a ?0? activates the hardware handshaking interface to handle source/destination requests for the specific channel. writing a ?1? activates the software handshaking interface to handle source/destination requests. ? ii. if the hardware handshaking interface is activated for the source or destination peripheral, assign handshaking interface to the source and destination peripheral. this requires programming the src_per and dest_per bits, respectively. 4. after the dmaca selected channel has been programmed, enable the channel by writ- ing a ?1? to the chenreg.ch_en bit. make sure that bit 0 of the dmacfgreg register is enabled. 5. source and destination request single and burst dmaca transactions to transfer the block of data (assuming non-memory peripherals). the dmaca acknowledges on com- pletion of each burst/single transaction and carry out the block transfer. 6. when the block transfer has completed, the dmaca reloads the sarx, darx and ctlx registers. hardware sets the block complete interrupt. the dmaca then sam- ples the row number as shown in table 19-1 on page 326 . if the dmaca is in row 1, then the dma transfer has completed. hardware sets the transfer complete interrupt and disables the channel. so you can either respond to the block complete or transfer complete interrupts, or poll for the channel enable (chenreg.ch_en) bit until it is dis- abled, to detect when the transfer is complete. if the dmaca is not in row 1, the next step is performed. 7. the dma transfer proceeds as follows: a. if interrupts are enabled (ctlx.int_en = 1) and the block complete interrupt is un- masked (maskblock[x] = 1?b1, where x is the channel number) hardware sets the block complete interrupt when the block transfer has completed. it then stalls until the block complete interrupt is cleared by software. if the next block is to be the last block in the dma transfer, then the block complete isr (interrupt service routine)
335 32072d?04/2011 at32uc3a3/a4 should clear the reload bits in the cfgx.reload_sr and cfgx.reload_ds registers. this put the dmaca into row 1 as shown in table 19-1 on page 326 . if the next block is not the last block in the dma transfer, then the reload bits should remain enabled to keep the dmaca in row 4. b. if interrupts are disabled (ctlx.int_en = 0) or the block complete interrupt is masked (maskblock[x] = 1?b0, where x is the channel number), then hardware does not stall until it detects a write to the block complete interrupt clear register but starts the next block transfer immediately. in this case software must clear the reload bits in the cfgx.reload_sr and cfgx.reload_ds registers to put the dmaca into row 1 of table 19-1 on page 326 before the last block of the dma transfer has completed. the transfer is similar to that shown in figure 19-11 on page 335 . the dma transfer flow is shown in figure 19-12 on page 336 . figure 19-11. multi-block dma transfer with source and destination address auto-reloaded address of source layer address of destination layer source blocks destination blocks blockn block2 block1 block0 sar dar
336 32072d?04/2011 at32uc3a3/a4 figure 19-12. dma transfer flow for source and destination address auto-reloaded 19.10.1.4 multi-block transfer with source address auto-reloaded and linked list destination address (row7) 1. read the channel enable register to choose a free (disabled) channel. 2. set up the chain of linked list items (otherwise known as block descriptors) in memory. write the control information in the lli.ctlx register location of the block descriptor for each lli in memory for channel x. for example, in the register you can program the following: a. set up the transfer type (memory or non-memory peripheral for source and desti- nation) and flow control peripheral by programming the tt_fc of the ctlx register. b. set up the transfer characteristics, such as: ? i. transfer width for the source in the src_tr_width field. ? ii. transfer width for the destination in the dst_tr_width field. ? iii. source master layer in th e sms field where source resides. ? iv. destination master layer in the dms field where destination resides. ? v. incrementing/decrementing or fixed address for source in sinc field. ? vi. incrementing/decrementing or fixed address for destination dinc field. channel enabled by software block transfer reload sarx, darx, ctlx channel disabled by hardware block complete interrupt generated here dmac transfer complete interrupt generated here yes no yes stall until block complete interrupt cleared by software ctlx.int_en=1 && maskblock[x]=1? no is dmac in row1 of dmac state machine table?
337 32072d?04/2011 at32uc3a3/a4 3. write the starting source address in the sarx register for channel x. note: the values in the lli.sarx register locations of each of the linked list items (llis) setup up in memory, although fetched during a lli fetch, are not used. 4. write the channel configuration information into the cfgx register for channel x. a. designate the handshaking interface type (hardware or software) for the source and destination peripherals. this is not required for memory. this step requires pro- gramming the hs_sel_src/hs_sel_dst bits, respectively. writing a ?0? activates the hardware handshaking interface to handle source/destination requests for the specific channel. writing a ?1? activates the software handshaking interface source/destination requests. b. if the hardware handshaking interface is activated for the source or destination peripheral, assign handshaking interface to the source and destination peripheral. this requires programming the src_per and dest_per bits, respectively. 5. make sure that the lli.ctlx register locations of all llis in memory (except the last) are set as shown in row 7 of table 19-1 on page 326 while the lli.ctlx register of the last linked list item must be set as described in row 1 or row 5 of table 19-1 on page 326 . figure 19-7 on page 325 shows a linked list example with two list items. 6. make sure that the lli.llpx register locations of all llis in memory (except the last) are non-zero and point to the next linked list item. 7. make sure that the lli.darx register location of all llis in memory point to the start destination block address proceeding that lli fetch. 8. make sure that the lli.ctlx.done field of the lli.ctlx register locations of all llis in memory is cleared. 9. clear any pending interrupts on the channel from the previous dma transfer by writing to the interrupt clear registers: cleartfr, clearblock, clearsrctran, cleardsttran, clearerr. reading the interrupt raw status and interrupt status registers confirms that all interrupts have been cleared. 10. program the ctlx, cfgx registers according to row 7 as shown in table 19-1 on page 326 . 11. program the llpx register with llpx(0), the pointer to the first linked list item. 12. finally, enable the channel by writing a ?1? to the chenreg.ch_en bit. the transfer is performed. make sure that bit 0 of the dmacfgreg register is enabled. 13. the dmaca fetches the first lli from the location pointed to by llpx(0). note: the lli.sarx, lli.darx, lli. llpx and lli.ct lx registers are fetched. the lli.sarx register although fetched is not used. 14. source and destination request single and burst dmaca transactions to transfer the block of data (assuming non-memory peripherals). dmaca acknowledges at the com- pletion of every transaction (burst and single) in the block and carry out the block transfer. 15. table 19-1 on page 326 the dmaca reloads the sarx regi ster from the initial value. hardware sets the block complete interrupt. the dmaca samples the row number as shown in table 19-1 on page 326 . if the dmaca is in row 1 or 5, then the dma trans- fer has completed. hardware sets the transfer complete interrupt and disables the channel. you can either respond to the block complete or transfer complete interrupts, or poll for the channel enable (chenreg.ch_en) bit until it is cleared by hardware, to detect when the transfer is complete. if the dmaca is not in row 1 or 5 as shown in table 19-1 on page 326 the following steps are performed. 16. the dma transfer proceeds as follows: a. if interrupts are enabled (ctlx.int_en = 1) and the block complete interrupt is un- masked (maskblock[x] = 1?b1, where x is the channel number) hardware sets the
338 32072d?04/2011 at32uc3a3/a4 block complete interrupt when the block transfer has completed. it then stalls until the block complete interrupt is cleared by software. if the next block is to be the last block in the dma transfer, then the block complete isr (interrupt service routine) should clear the cfgx.reload_sr source reload bit. this puts the dmaca into row1 as shown in table 19-1 on page 326 . if the next block is not the last block in the dma transfer, then the source reload bit should remain enabled to keep the dmaca in row 7 as shown in table 19-1 on page 326 . b. if interrupts are disabled (ctlx.int_en = 0) or the block complete interrupt is masked (maskblock[x] = 1?b0, where x is the channel number) then hardware does not stall until it detects a write to the block complete interrupt clear register but starts the next block transfer immediately. in this case, software must clear the source reload bit, cfgx.reload_sr, to put the device into row 1 of table 19-1 on page 326 before the last block of the dma transfer has completed. 17. the dmaca fetches the next lli from memory location pointed to by the current llpx register, and automatically reprograms the darx, ctlx and llpx channel registers. note that the sarx is not re-programmed as the reloaded value is used for the next dma block transfer. if the next block is the last block of the dma transfer then the ctlx and llpx registers just fetched from the lli should match row 1 or row 5 of table 19- 1 on page 326 . the dma transfer might look like that shown in figure 19-13 on page 338 . figure 19-13. multi-block dma transfer with source address auto-reloaded and linked list destination address the dma transfer flow is shown in figure 19-14 on page 339 . address of source layer address of destination layer source blocks destination blocks sar block0 block1 block2 blockn dar(n) dar(1) dar(0) dar(2)
339 32072d?04/2011 at32uc3a3/a4 figure 19-14. dma transfer flow for source address auto-reloaded and linked list destina- tion address channel enabled by software lli fetch yes no no yes hardware reprograms darx, ctlx, llpx dmac block transfer source/destination status fetch reload sarx block complete interrupt generated here dmac transfer complete interrupt generated here channel disabled by hardware ctlx.int_en=1 && maskblock[x]=1 ? stall until block interrupt cleared by hardware is dmac in row1 or row5 of dmac state machine table?
340 32072d?04/2011 at32uc3a3/a4 19.10.1.5 multi-block transfer with source address auto-reloaded and contiguous destination address (row 3) 1. read the channel enable register to choose a free (disabled) channel. 2. clear any pending interrupts on the channel from the previous dma transfer by writing a ?1? to the interrupt clear registers: cleartfr, clearblock, clearsrctran, cleardsttran, clearerr. reading the interrupt raw status and interrupt status registers confirms that all interrupts have been cleared. 3. program the following channel registers: a. write the starting source address in the sarx register for channel x. b. write the starting destination address in the darx register for channel x. c. program ctlx and cfgx according to row 3 as shown in table 19-1 on page 326 . program the llpx register with ?0?. d. write the control information for the dma transfer in the ctlx register for channel x. for example, in this register, you can program the following: ? i. set up the transfer type (memory or non-memory peripheral for source and destination) and flow control device by programming the tt_fc of the ctlx register. ? ii. set up the transfer characteristics, such as: ? transfer width for the source in the src_tr_width field. ? transfer width for the destination in the dst_tr_width field. ? source master layer in the sms field where source resides. ? destination master layer in the dms field where destination resides. ? incrementing/decrementing or fixed address for source in sinc field. ? incrementing/decrementing or fixed address for destination in dinc field. e. write the channel configuration information into the cfgx register for channel x. ? i. designate the handshaking interface type (hardware or software) for the source and destination peripherals. this is not required for memory. this step requires programming the hs_sel_src/hs_sel_dst bits, respectively. writing a ?0? activates the hardware handshaking interface to handle source/destination requests for the specific channel. writing a ?1? activates the software handshaking interface to handle source/destination requests. ? ii. if the hardware handshaking interface is activated for the source or destination peripheral, assign handshaking interface to the source and destination peripheral. this requires programming the src_per and dest_per bits, respectively. 4. after the dmaca channel has been programmed, enable the channel by writing a ?1? to the chenreg.ch_en bit. make sure that bit 0 of the dmacfgreg register is enabled. 5. source and destination request single and burst dmaca transactions to transfer the block of data (assuming non-memory peripherals). the dmaca acknowledges at the completion of every transaction (burst and single) in the block and carries out the block transfer. 6. when the block transfer has completed, the dmaca reloads the sarx register. the darx register remains unchanged. hardware sets the block complete interrupt. the dmaca then samples the row number as shown in table 19-1 on page 326 . if the dmaca is in row 1, then the dma transfer has completed. hardware sets the transfer complete interrupt and disables the channel. so you can either respond to the block complete or transfer complete interrupts, or poll for the channel enable (chen-
341 32072d?04/2011 at32uc3a3/a4 reg.ch_en) bit until it is cleared by hardware, to detect when the transfer is complete. if the dmaca is not in row 1, the next step is performed. 7. the dma transfer proceeds as follows: a. if interrupts are enabled (ctlx.int_en = 1) and the block complete interrupt is un- masked (maskblock[x] = 1?b1, where x is the channel number) hardware sets the block complete interrupt when the block transfer has completed. it then stalls until the block complete interrupt is cleared by software. if the next block is to be the last block in the dma transfer, then the block complete isr (interrupt service routine) should clear the source reload bit, cfgx.reload_sr. this puts the dmaca into row1 as shown in table 19-1 on page 326 . if the next block is not the last block in the dma transfer then the source reload bit should remain enabled to keep the dmaca in row3 as shown in table 19-1 on page 326 . b. if interrupts are disabled (ctlx.int_en = 0) or the block complete interrupt is masked (maskblock[x] = 1?b0, where x is the channel number) then hardware does not stall until it detects a write to the block complete interrupt clear register but starts the next block transfer immediately. in this case software must clear the source reload bit, cfgx.reload_sr, to put the device into row 1 of table 19-1 on page 326 before the last block of the dma transfer has completed. the transfer is similar to that shown in figure 19-15 on page 341 . the dma transfer flow is shown in figure 19-16 on page 342 . figure 19-15. multi-block transfer with source address auto-reloaded and contiguous desti- nation address address of source layer address of destination layer source blocks destination blocks sar block0 block1 block2 dar(1) dar(0) dar(2)
342 32072d?04/2011 at32uc3a3/a4 figure 19-16. dma transfer for source address auto-reloaded and contiguous destination address 19.10.1.6 multi-block dma transfer with linked list for source and contiguous destination address (row 8) 1. read the channel enable register to choose a free (disabled) channel. 2. set up the linked list in memory. write the control information in the lli. ctlx register location of the block descriptor for each lli in memory for channel x. for example, in the register, you can program the following: a. set up the transfer type (memory or non-memory peripheral for source and desti- nation) and flow control device by programming the tt_fc of the ctlx register. b. set up the transfer characteristics, such as: ? i. transfer width for the source in the src_tr_width field. ? ii. transfer width for the destination in the dst_tr_width field. ? iii. source master layer in th e sms field where source resides. ? iv. destination master layer in the dms field where destination resides. channel enabled by software block transfer reload sarx, ctlx channel disabled by hardware block complete interrupt generated here dmac transfer complete interrupt generated here yes no no yes stall until block complete interrupt cleared by software ctlx.int_en=1 && maskblock[x]=1? is dmac in row1 of dmac state machine table?
343 32072d?04/2011 at32uc3a3/a4 ? v. incrementing/decrementing or fixed address for source in sinc field. ? vi. incrementing/decrementing or fixed address for destination dinc field. 3. write the starting destination address in the darx register for channel x. note: the values in the lli.darx register location of each linked list item (lli) in memory, although fetched during an lli fetch, are not used. 4. write the channel configuration information into the cfgx register for channel x. a. designate the handshaking interface type (hardware or software) for the source and destination peripherals. this is not required for memory. this step requires pro- gramming the hs_sel_src/hs_sel_dst bits, respectively. writing a ?0? activates the hardware handshaking interface to handle source/destination requests for the specific channel. writing a ?1? activates the software handshaking interface to handle source/destination requests. b. if the hardware handshaking interface is activated for the source or destination peripheral, assign handshaking interface to the source and destination peripherals. this requires programming the src_per and dest_per bits, respectively. 5. make sure that all lli.ctlx register locations of the lli (except the last) are set as shown in row 8 of table 19-1 on page 326 , while the lli.ctlx register of the last linked list item must be set as described in row 1 or row 5 of table 19-1 on page 326 . figure 19-7 on page 325 shows a linked list example with two list items. 6. make sure that the lli.llpx register locations of all llis in memory (except the last) are non-zero and point to the next linked list item. 7. make sure that the lli.sarx register location of all llis in memory point to the start source block address proceeding that lli fetch. 8. make sure that the lli.ctlx.done field of the lli.ctlx register locations of all llis in memory is cleared. 9. clear any pending interrupts on the channel from the previous dma transfer by writing a ?1? to the interrupt clear registers: cleartfr, clearblock, clearsrctran, cleardsttran, clearerr. reading the interrupt raw status and interrupt status registers confirms that all interrupts have been cleared. 10. program the ctlx, cfgx registers according to row 8 as shown in table 19-1 on page 326 11. program the llpx register with llpx(0), the pointer to the first linked list item. 12. finally, enable the channel by writing a ?1? to the chenreg.ch_en bit. the transfer is performed. make sure that bit 0 of the dmacfgreg register is enabled. 13. the dmaca fetches the first lli from the location pointed to by llpx(0). note: the lli.sarx, lli.darx, lli.llpx and lli.ct lx registers are fetched . the lli.darx register location of the lli although fetched is not used. the darx register in the dmaca remains unchanged. 14. source and destination requests single and burst dmaca transactions to transfer the block of data (assuming non-memory peripherals). the dmaca acknowledges at the completion of every transaction (burst and single) in the block and carry out the block transfer. note: 15. the dmaca does not wait for the block interrupt to be cleared, but continues and fetches the next lli from the memory location pointed to by current llpx register and automatically reprograms the sarx, ctlx and llpx channel registers. the darx reg- ister is left unchanged. the dma transfer continues until the dmaca samples the ctlx and llpx registers at the end of a block transfer match that described in row 1 or row
344 32072d?04/2011 at32uc3a3/a4 5 of table 19-1 on page 326 . the dmaca then knows that the previous block trans- ferred was the last block in the dma transfer. the dmaca transfer might look like that shown in figure 19-17 on page 344 note that the des- tination address is decrementing. figure 19-17. dma transfer with linked list source address and contiguous destination address the dma transfer flow is shown in figure 19-19 on page 345 . figure 19-18. sar(2) sar(1) sar(0) dar(2) dar(1) dar(0) block 2 block 1 block 0 block 0 block 1 block 2 address of source layer address of destination layer source blocks destination blocks
345 32072d?04/2011 at32uc3a3/a4 figure 19-19. dma transfer flow for source address auto-reloaded and contiguous destination address 19.11 disabling a channel prio r to transfer completion under normal operation, software enables a channel by writing a ?1? to the channel enable reg- ister, chenreg.ch_en, and hardware disables a ch annel on transfer completion by clearing the chenreg.ch_en register bit. the recommended way for software to disable a channel without losing data is to use the ch_susp bit in conjunction with the fifo_empty bit in the channel configuration register (cfgx) register. 1. if software wishes to disable a channel prior to the dma transfer completion, then it can set the cfgx.ch_susp bit to tell the dmaca to halt all transfers from the source peripheral. therefore, the channel fifo receives no new data. 2. software can now poll the cfgx.fifo_empty bit until it indicates that the channel fifo is empty. channel enabled by software lli fetch hardware reprograms sarx, ctlx, llpx dmac block transfer source/destination status fetch is dmac in row 1 of table 4 ? channel disabled by hardware block complete interrupt generated here dmac transfer complete interrupt generated here yes no
346 32072d?04/2011 at32uc3a3/a4 3. the chenreg.ch_en bit can then be cleared by software once the channel fifo is empty. when ctlx.src_tr_width is less than ct lx.dst_tr_width and the cfgx.ch_susp bit is high, the cfgx.fifo_empty is asserted once the contents of the fifo do not permit a single word of ctlx.dst_tr_width to be formed. however, there may still be data in the channel fifo but not enough to form a single transfer of ctlx.dst_tr_width width. in this configura- tion, once the channel is disabled, the remaining data in the channel fifo are not transferred to the destination peripheral. it is permitted to remove the channel from the suspension state by writing a ?0? to the cfgx.ch_su sp register. the dma transfer completes in the normal manner. note: if a channel is disabled by software, an active single or burst transaction is not guaranteed to receive an acknowledgement. 19.11.1 abnormal transfer termination a dmaca dma transfer may be terminated abruptly by software by clearing the channel enable bit, chenreg.ch_en. this does not mean that th e channel is disabled immediately after the chenreg.ch_en bit is cleared over the hsb slave interface. consider this as a request to dis- able the channel. the chenreg.ch_en must be polled and then it must be confirmed that the channel is disabled by reading back 0. a case where the channel is not be disabled after a chan- nel disable request is where either the source or destination has received a split or retry response. the dmaca must keep re-attempting the transfer to the system haddr that origi- nally received the sp lit or retry response unt il an okay response is retu rned. to do otherwise is an system bus protocol violation. software may terminate all channels abruptly by clearing the global enable bit in the dmaca configuration register (dmacfgreg[0]). again, this does not mean that all channels are dis- abled immediately after the dmacfgreg[0] is cleared over the hsb slave interface. consider this as a request to disable all channels. the chenreg must be polled and then it must be con- firmed that all channels are disabled by reading back ?0?. note: if the channel enable bit is cleared while there is data in the channel fifo, this data is not sent to the destination peripheral and is not present when the channel is re-enabled. for read sensitive source peripherals such as a sour ce fifo this data is therefor e lost. when the source is not a read sensitive device (i.e., memory), disabling a channel without waiting for the channel fifo to empty may be acceptable as the data is available from the source peripheral upon request and is not lost. note: if a channel is disabled by software, an active single or burst transaction is not guaranteed to receive an acknowledgement.
347 32072d?04/2011 at32uc3a3/a4 19.12 user interface table 19-2. dma controller memory map offset register register name access reset value 0x000 channel 0 source address register sar0 read/write 0x00000000 0x008 channel 0 destination addres s register dar0 read/write 0x00000000 0x010 channel 0 linked list pointer register llp0 read/write 0x00000000 0x018 channel 0 control register low ctl0l read/write 0x00304801 0x01c channel 0 control register high ctl0h read/write 0x00000002 0x040 channel 0 configuration register low cfg0l read/write 0x00000c00 0x044 channel 0 configuration register high cfg0h read/write 0x00000004 0x048 channel 0 source gather register sgr0 read/write 0x00000000 0x050 channel 0 destination scatter register dsr0 read/write 0x00000000 0x058 channel 1 source address register sar1 read/write 0x00000000 0x060 channel 1 destination addres s register dar1 read/write 0x00000000 0x068 channel 1 linked list pointer register llp1 read/write 0x00000000 0x070 channel 1 control register low ctl1l read/write 0x00304801 0x074 channel 1 control register high ctl1h read/write 0x00000002 0x098 channel 1 configuration register low cfg1l read/write 0x00000c20 0x09c channel 1 configuration register high cfg1h read/write 0x00000004 0x0a0 channel 1source gather register sgr1 read/write 0x00000000 0x0a8 channel 1 destination scatter register dsr1 read/write 0x00000000 0x0b0 channel 2 source address register sar2 read/write 0x00000000 0x0b8 channel 2 destination address register dar2 read/write 0x00000000 0x0c0 channel 2 linked list pointer register llp2 read/write 0x00000000 0x0c8 channel 2 control register low ctl2l read/write 0x00304801 0x0cc channel 2 control register high ctl2h read/write 0x00000002 0x0f0 channel 2 configuration register low cfg2l read/write 0x00000c40 0x0f4 channel 2 configuration register high cfg2h read/write 0x00000004 0x0f8 channel 2 source gather register sgr2 read/write 0x00000000 0x100 channel 2 destination scatter register dsr2 read/write 0x00000000 0x108 channel 3 source address register sar3 read/write 0x00000000 0x110 channel 3 destination addres s register dar3 read/write 0x00000000 0x118 channel 3 linked list pointer register llp3 read/write 0x00000000 0x120 channel 3 control register low ctl3l read/write 0x00304801 0x124 channel 3 control register high ctl3h read/write 0x00000002 0x148 channel 3 configuration register low cfg3l read/write 0x00000c60 0x14c channel 3 configuration register high cfg3h read/write 0x00000004 0x150 channel 3 source gather register sgr3 read/write 0x00000000
348 32072d?04/2011 at32uc3a3/a4 0x158 channel 3destination scatter register dsr3 read/write 0x00000000 0x2c0 raw status for inttfr interrupt rawtfr read-only 0x00000000 0x2c8 raw status for intblock interrupt rawblock read-only 0x00000000 0x2d0 raw status for intsrctran interrupt rawsrctran read-only 0x00000000 0x2d8 raw status for intdsttran interrupt rawdsttran read-only 0x00000000 0x2e0 raw status for interr interrupt rawerr read-only 0x00000000 0x2e8 status for inttfr interrupt statustfr read-only 0x00000000 0x2f0 status for intblock interrupt statusblock read-only 0x00000000 0x2f8 status for intsrctran interrupt statussrctran read-only 0x00000000 0x300 status for intdsttran interrupt statusdsttran read-only 0x00000000 0x308 status for interr interr upt statuserr read-only 0x00000000 0x310 mask for inttfr interrupt masktfr read/write 0x00000000 0x318 mask for intblock interrupt maskblock read/write 0x00000000 0x320 mask for intsrctran interrupt masksrctran read/write 0x00000000 0x328 mask for intdsttran interrupt maskdsttran read/write 0x00000000 0x330 mask for interr interrupt maskerr read/write 0x00000000 0x338 clear for inttfr interrupt cleartfr write-only 0x00000000 0x340 clear for intblock interrupt clearblock write-only 0x00000000 0x348 clear for intsrctran interrupt clearsrctran write-only 0x00000000 0x350 clear for intdsttran interrupt cleardsttran write-only 0x00000000 0x358 clear for interr interrupt clearerr write-only 0x00000000 0x360 status for each interrupt type statusint read-only 0x00000000 0x368 source software transaction request register reqsrcreg read/write 0x00000000 0x370 destination software transaction re quest register reqdstreg read/write 0x00000000 0x378 single source transaction request register sglreqsrcreg read/write 0x00000000 0x380 single destination transaction request register sglreqdstreg read/write 0x00000000 0x388 last source transaction request register lstsrcreg read/write 0x00000000 0x390 last destination transaction request register lstdstreg read/write 0x00000000 0x398 dma configuration register dmacfgreg read/write 0x00000000 0x3a0 dma channel enable register chenreg read/write 0x00000000 0x3f8 dma component id register low dmacompidregl read-only 0x44571110 0x3fc dma component id register high dmacompidregh read-only 0x3230362a table 19-2. dma controller memory map (continued) offset register register name access reset value
349 32072d?04/2011 at32uc3a3/a4 19.12.1 channel x source address register name: sarx access type: read/write offset: 0x000 + [x * 0x58] reset value: 0x00000000 ? sadd: source address of dma transfer the starting system bus source address is programmed by software before the dma channel is enabled or by a lli update before the start of the dma transfer. as the dma transfer is in progress, this register is updated to reflect the source address of the current system bus transfer. updated after each source system bus transfer. the sinc field in the ctlx register determines whether the address incre- ments, decrements, or is left unchanged on every source system bus transfer throughout the block transfer. 31 30 29 28 27 26 25 24 sadd[31:24] 23 22 21 20 19 18 17 16 sadd[23:16] 15 14 13 12 11 10 9 8 sadd[15:8] 76543210 sadd[7:0]
350 32072d?04/2011 at32uc3a3/a4 19.12.2 channel x destination address register name: darx access type: read/write offset: 0x008 + [x * 0x58] reset value: 0x00000000 ? dadd: destination address of dma transfer the starting system bus destination address is programmed by software before the dma channel is enabled or by a lli update before the start of the dma transfer. as the dma transfer is in progress, this register is updated to reflect the desti- nation address of the current system bus transfer. updated after each destination system bus transfer. the dinc fi eld in the ctlx register determines whether the address increments, decrements or is left unchanged on every destination system bus transfer throughout the block transfer. 31 30 29 28 27 26 25 24 dadd[31:24] 23 22 21 20 19 18 17 16 dadd[23:16] 15 14 13 12 11 10 9 8 dadd[15:8] 76543210 dadd[7:0]
351 32072d?04/2011 at32uc3a3/a4 19.12.3 linked list pointer register for channel x name: llpx access type: read/write offset: 0x010 + [x * 0x58] reset value: 0x00000000 ? loc: address of the next lli starting address in memory of next lli if block chaining is enabled. the user need to program this register to point to the first linked list item (lli) in memory prior to enabling the channel if block chaining is enabled. the llp register has two functions: the logical result of the equation llp.loc != 0 is used to set up the type of dma transfer (single or multi-block). if llp.loc is set to 0x0, then transfers using linked lists are not enabled. this register must be programmed prior to enabling the channel in order to set up the transfer type. it (llp.loc != 0) contains the pointer to the next linked listed item for block chaining using linked lists. in this case, loc[29:0] corresponds to a[31:2] of the next linked listed item address the llpx register is also used to point to the address where write back of the control and source/destination status infor- mation occurs afte r block completion. ? lms: list master select identifies the high speed bus interface for the device that stores the next linked list item: 31 30 29 28 27 26 25 24 loc[29:22] 23 22 21 20 19 18 17 16 loc[21:14] 15 14 13 12 11 10 9 8 loc[13:6] 76543210 loc[5:0] lms table 19-3. list master select lms hsb master 0 hsb master 1 1 hsb master 2 other reserved
352 32072d?04/2011 at32uc3a3/a4 19.12.4 control register for channel x low name: ctlxl access type: read/write offset: 0x018 + [x * 0x58] reset value: 0x00304801 this register contains fields that control the dma transfer. t he ctlxl register is part of the block descriptor (linked list it em) when block chaining is enabled. it can be varied on a block-by-block basis within a dma transfer when block chaining is enabled. ? llp_src_en block chaining is only enabled on the source side if the llp_src_en field is high and llpx.loc is non-zero. ? llp_dst_en block chaining is only enabled on the destination side if the llp_dst_en field is high and llpx.loc is non-zero. ? sms: source master select identifies the master interface layer where the source device (peripheral or memory) is accessed from 31 30 29 28 27 26 25 24 llp_src_e n llp_dst_e n sms dms[1] 23 22 21 20 19 18 17 16 dms[0] tt_fc dst_gathe r_en src_gathe r_en src_msize [2] 15 14 13 12 11 10 9 8 src_msize[1:0] dest_msize sinc dinc[1] 76543210 dinc[0] src_tr_width dst_tr_width int_en table 19-4. source master select sms hsb master 0 hsb master 1 1 hsb master 2 other reserved
353 32072d?04/2011 at32uc3a3/a4 ?dms: destination master select identifies the master interface layer where the destination device (peripheral or memory) resides ? tt_fc: transfer type and flow control the four following transfer types are supported: ? memory to memory, memory to peripheral, peripheral to memory and peripheral to peripheral. the dmaca is always the flow controller. ? dst_scatter_en: destination scatter enable 0 = scatter disabled 1 = scatter enabled scatter on the destination side is applicable only when the ctl x .dinc bit indicates an incrementing or decrementing address control. ? src_gather_en: source gather enable 0 = gather disabled 1 = gather enabled gather on the source side is applicable only when the ctl x .sinc bit indicates an incrementing or decrementing address control. ? src_msize: source burst transaction length number of data items, each of width ctlx.src_tr_width , to be read from the source every time a source burst transac- tion request is made from either the correspondi ng hardware or software handshaking interface. table 19-5. destination master select dms hsb master 0 hsb master 1 1 hsb master 2 other reserved tt_fc transfer type flow controller 000 memory to memory dmaca 001 memory to peripheral dmaca 010 peripheral to memory dmaca 011 peripheral to peripheral dmaca other reserved reserved src_msize size (items number) 01 14 28
354 32072d?04/2011 at32uc3a3/a4 ? dst_msize: destination burst transaction length number of data items, each of width ctlx.dst_tr_width , to be written to the destination every time a destination burst transaction request is made from either the corres ponding hardware or software handshaking interface. ?sinc: source address increment indicates whether to increment or decrement the source addres s on every source system bus transfer. if your device is fetching data from a source peripheral fifo with a fixed address, then set this field to ?no change? ? dinc: destination address increment indicates whether to increment or decrement the destination address on every destination system bus transfer. if your device is writing data to a destination peripheral fifo with a fixed address, then set this field to ?no change? 316 432 other reserved dst_msize size (items number) 01 14 28 316 432 other reserved sinc source address increment 0 increment 1 decrement other no change dinc destination address increment 0 increment 1 decrement other no change src_msize size (items number)
355 32072d?04/2011 at32uc3a3/a4 ? srt_tr_width: source transfer width ? dsc_tr_width: destin ation transfer width ? int_en: interrupt enable bit if set, then all five interrupt generating sources are enabled. src_tr_width/dst_tr_width size (bits) 08 116 232 other reserved
356 32072d?04/2011 at32uc3a3/a4 19.12.5 control register for channel x high name: ctlxh access type: read/write offset: 0x01c + [x * 0x58] reset value: 0x00000002 ? done: done bit software can poll this bit to see when a block transfer is complete ? block_ts: block transfer size when the dmaca is flow controller, this fi eld is written by the user before the channel is enabled to indicate the block size. the number programmed into block_ts indicates the total number of single transactions to perform for every block transfer, unless the transfer is already in progress, in which case the value of block_ts indicates the number of single transactions that have been performed so far. the width of the single transaction is determined by ctlx.src_tr_width. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - done block_ts[11:8] 76543210 block_ts[7:0]
357 32072d?04/2011 at32uc3a3/a4 19.12.6 configuration register for channel x low name: cfgxl access type: read/write offset: 0x040 + [x * 0x58] ? reset value: 0x00000c00 + [x * 0x20] ? reload_dst: automatic destination reload the darx register can be automatically reloaded from its initial value at the end of every block for multi-block transfers. a new block transfer is then initiated. ? reload_src: automatic source reload the sarx register can be automatically reloaded from its initial value at the end of every block for multi-block transfers. a new block transfer is then initiated. ? src_hs_pol: source handshaking interface polarity 0 = active high 1 = active low ? dst_hs_pol: destination handshaking interface polarity 0 = active high 1 = active low ? hs_sel_src: source software or hardware handshaking select this register selects which of the handshaking interfaces, hardware or software, is active for source requests on this channel. 0 = hardware handshaking interface. software-i nitiated transaction requests are ignored. 1 = software handshaking interface. hardware-initiated transaction requests are ignored. if the source peripheral is memory, then this bit is ignored. ? hs_sel_dst: destination software or hardware handshaking select this register selects which of the handshaking interfaces, hardware or software, is active for destination requests on this channel. 31 30 29 28 27 26 25 24 reload_d st reload_s rc ------ 23 22 21 20 19 18 17 16 - - - - src_hs_p ol dst_hs_po l -- 15 14 13 12 11 10 9 8 --hs_sel_sr c hs_sel_ds t fifo_empt y ch_susp 76543210 ch_prior - - - - -
358 32072d?04/2011 at32uc3a3/a4 0 = hardware handshaking interface. software-i nitiated transaction requests are ignored. 1 = software handshaking interface. hardware initiated transaction requests are ignored. if the destination peripheral is memory, then this bit is ignored. ? fifo_empty indicates if there is data left in the channel's fifo. can be used in conjunction with cfgx .ch_susp to cleanly disable a channel. 1 = channel's fifo empty 0 = channel's fifo not empty ? ch_susp: channel suspend suspends all dma data transfers from the source until this bit is cleared. there is no guarantee that the current transaction will complete. can also be used in conjunction with cf gx.fifo_empty to cleanly disable a channel without losing any data. 0 = not suspended. 1 = suspend. suspend dma transfer from the source. ? ch_prior: channel priority a priority of 7 is the highest priority, and 0 is the lowest. this field must be programmed within the following range [0, x-1] . a programmed value outside this range causes erroneous behavior.
359 32072d?04/2011 at32uc3a3/a4 19.12.7 configuration register for channel x high name: cfgxh access type: read/write offset: 0x044 + [x * 0x58] reset value: 0x00000004 ? dest_per: destination hardware handshaking interface assigns a hardware handshaking interface (0 - dm ah_num_hs_int-1) to th e destination of channel x if the cfgx.hs_sel_dst field is 0. otherwise, this field is ignored. the channel can then communicate with the destination peripheral connected to that interface via the assigned hardware handshaking interface. for correct dma operation, only one peripheral (source or destination) should be assigned to the same handshaking interface. ? src_per: source hardware handshaking interface assigns a hardware handshaking interface (0 - dmah_num_hs_int-1) to the source of channel x if the cfgx.hs_sel_src field is 0. otherwise, this field is ignored. the channel can then communicate with the source periph- eral connected to that interface via th e assigned hardware handshaking interface. for correct dmaca operation, only one peripheral (source or destination) should be assigned to the same handshaking interface. ?protctl: protection control bits used to drive the system bus hprot[3:1] bus. the system bus specification recommends that the default value of hprot indicates a non-cached, nonbuffered, privileged data access. the reset value is used to indicate such an access. hprot[0] is tied high as all transfers are data accesses as there are no opcode fetches. there is a one-to-one mapping of these register bits to the hprot[3:1] master interface signals. ?fifo_mode: r/w 0x0 fifo mode select determines how much space or data needs to be available in the fifo before a burst transaction request is serviced. 0 = space/data available for single system bu s transfer of the specified transfer width. 1 = space/data available is greater than or equal to half the fifo depth for destination transfe rs and less than half the fifo depth for source transfers. the exceptions are at the end of a burst transaction request or at the end of a block transfer. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - dest_per src_per[3:1] 76543210 src_per[0] - - protctl fifo_mode fcmode
360 32072d?04/2011 at32uc3a3/a4 ?fcmode: flow control mode determines when source transaction requests are serviced when the destination peripheral is the flow controller. 0 = source transaction requests are serviced when they occur. data pre-fetching is enabled. 1 = source transaction requests are not serviced until a destinatio n transaction request occurs. in this mode the amount of dat a transferred from the source is limited such that it is guaranteed to be transferred to the destination prior to block terminati on by the destination. data pre-fetching is disabled.
361 32072d?04/2011 at32uc3a3/a4 19.12.8 source gather register for channel x name: sgrx access type: read/write offset: 0x048 + [x * 0x58] reset value: 0x00000000 ? sgc: source gather count specifies the number of contiguous source transfers of ctl x .src_tr_width between successive gather intervals. this is defined as a gather boundary. ?sgi: source gather interval specifies the source address increment/decrement in multiples of ctl x .src_tr_width on a gather boundary when gather mode is enabled for the source transfer. 31 30 29 28 27 26 25 24 sgc[11:4] 23 22 21 20 19 18 17 16 sgc[3:0] sgi[19:16] 15 14 13 12 11 10 9 8 sgi[15:8] 76543210 sgi[7:0]
362 32072d?04/2011 at32uc3a3/a4 19.12.9 destination scatter register for channel x name: dsrx access type: read/write offset: 0x050 + [x * 0x58] reset value: 0x00000000 ? dsc: destination scatter count specifies the number of contiguous destination transfers of ctl x .dst_tr_width between successive scatter boundaries. ?dsi: destination scatter interval specifies the destination address increment/decrement in multiples of ctl x .dst_tr_width on a scatter boundary when scatter mode is enabled for the destination transfer. 31 30 29 28 27 26 25 24 dsc[11:4] 23 22 21 20 19 18 17 16 dsc[3:0] dsi[19:16] 15 14 13 12 11 10 9 8 dsi[15:8] 76543210 dsi[7:0]
363 32072d?04/2011 at32uc3a3/a4 19.12.10 interrupt registers the following sections describe the registers pertaining to interrupts, their status, and how to clear them. for each channel, there are five types of interrupt sources: ? inttfr: dma transfer complete interrupt this interrupt is generated on dma transfer completion to the destination peripheral. ? intblock: block transfer complete interrupt this interrupt is generated on dma block transfer completion to the destination peripheral. ? intsrctran: source transaction complete interrupt this interrupt is generated after completion of the last sy stem bus transfer of the requested single/burst transaction from the handshaking interface on the source side. if the source for a channel is memory, then that channel never generates a intsrctran interrupt and hence the correspond- ing bit in this field is not set. ? intdsttran: destination transaction complete interrupt this interrupt is generated after completion of the last sy stem bus transfer of the requested single/burst transaction from the handshaking interface on the destination side. if the destination for a channel is memory, then that channel never generates the intdsttran interrupt and hence the corre- sponding bit in this field is not set. ? interr: error interrupt this interrupt is generated when an error response is received from an hsb slave on the hresp bus during a dma transfer. in addition, the dma transfer is cancelled and the channel is disabled.
364 32072d?04/2011 at32uc3a3/a4 19.12.11 interrupt raw status registers name: rawtfr, rawblock, rawsrc tran, rawdsttran, rawerr access type: read-only offset: 0x2c0, 0x2c8, 0x2d0, 0x2d8, 0x2e0 reset value: 0x00000000 ? raw[3:0]raw interrupt for each channel interrupt events are stored in these raw interrupt status registers before masking: rawtfr, rawblock, rawsrctran, rawdsttran, rawerr. each raw interrupt status register has a bit allocated per channel, for example, rawtfr[2] is chan- nel 2?s raw transfer complete interrupt. each bit in these regi sters is cleared by writing a 1 to the corresponding location in the cleartfr, clear block, clearsrctran, cleards ttran, clearerr registers. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - - - raw3 raw2 raw1 raw0
365 32072d?04/2011 at32uc3a3/a4 19.12.12 interrupt status registers name: statustfr, statusblock, statussrctran, statusdsttran, statuserr access type: read-only offset: 0x2e8, 0x2f0, 0x2f8, 0x300, 0x308 reset value: 0x00000000 ? status[3:0] all interrupt events from all channels are stored in these interr upt status registers after masking: statustfr, statusblock, statussrctran, statusdsttran, statuserr. each interrupt status register has a bit allocated per channel, for example, sta- tustfr[2] is channel 2?s status transfer complete interrupt.the contents of these registers are used to generate the interrupt signals leaving the dmaca. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - - - status3 status2 status1 status0
366 32072d?04/2011 at32uc3a3/a4 19.12.13 interrupt mask registers name: masktfr, maskblock, masksrctran, maskdsttran, maskerr access type: read/write offset: 0x310, 0x318, 0x320, 0x328, 0x330 reset value: 0x00000000 the contents of the raw status registers are masked with the contents of the mask register s: masktfr, maskblock, mask- srctran, maskdsttran, maskerr. each interrupt mask register has a bit allocated per channel, for example, masktfr[2] is the mask bit for channel 2?s transfer complete interrupt. a channel?s int_mask bit is only writt en if the corresponding mask write enable bit in the in t_mask_we field is asserted on the same system bus write transfer. this allows software to set a mask bit without performing a read-modified write operation. for example, writing hex 01x1 to the masktfr register writes a 1 into masktfr[0], while masktfr[7:1] remains unchanged. writing hex 00 xx leaves masktfr[7:0] unchanged. writing a 1 to any bit in these registers unmasks the corresponding interrupt, thus allowing the dmaca to set the appropri- ate bit in the status registers. ? int_m_we[11:8]: interrupt mask write enable 0 = write disabled 1 = write enabled ? int_mask[3:0]: interrupt mask 0= masked 1 = unmasked 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - int_m_we3 int_m_we2 int_m_we1 int_m_we0 76543210 - - - - int_mask3 int_mask2 int_mask1 int_mask0
367 32072d?04/2011 at32uc3a3/a4 19.12.14 interrupt clear registers name: cleartfr, clearblo ck, clearsrctran, cle ardsttran, clearerr access type: write-only offset: 0x338, 0x340, 0x348, 0x350, 0x358 reset value: 0x00000000 ? clear[3:0]: interrupt clear 0 = no effect 1 = clear interrupt each bit in the raw status and status registers is cleared on the same cycle by writing a 1 to the corresponding location in the clear registers: cleartfr, clearblock, clearsrctran, cleardsttran, clearerr. each interrupt clear register has a bit allo- cated per channel, for example, cleartfr[2] is the clear bit fo r channel 2?s transfer complete interrupt. writing a 0 has no effect. these registers are not readable. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - - - clear3 clear2 clear1 clear0
368 32072d?04/2011 at32uc3a3/a4 19.12.15 combined interrupt status registers name: statusint access type: read-only offset: 0x360 reset value: 0x00000000 the contents of each of the five status registers (statustfr , statusblock, statussrctran, statusdsttran, statuserr) is or?ed to produce a single bit per interrupt type in the combined status register (statusint). ?err or of the contents of statuserr register. ?dstt or of the contents of statusdsttran register. ? srct or of the contents of statussrctran register. ?block or of the contents of statusblock register. ?tfr or of the contents of statustfr register. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - - err dstt srct block tfr
369 32072d?04/2011 at32uc3a3/a4 19.12.16 source software transaction request register name: reqsrcreg access type: read/write offset: 0x368 reset value: 0x00000000 a bit is assigned for each channel in this register. reqsrcreg[ n ] is ignored when software handshaking is not enabled for the source of channel n . a channel src_req bit is written only if the corresponding ch annel write enable bit in the req_we field is asserted on the same system bus write transfer. for example, writing 0x101 writes a 1 into reqsrcreg[0] , while reqsrcreg[4:1] remains unchanged. writing hex 0x0 yy leaves reqsrcreg[4:0] unchanged. this allows software to set a bit in the reqsrcreg register without performing a read- modified write ? req_we[11:8]: request write enable 0 = write disabled 1 = write enabled ? src_req[3:0]: source request 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - req_we3 req_we2 req_we1 req_we0 76543210 - - - - src_req3 src_req2 src_req1 src_req0
370 32072d?04/2011 at32uc3a3/a4 19.12.17 destination software transaction request register name: reqdstreg access type: read/write offset: 0x370 reset value: 0x00000000 a bit is assigned for each channel in this register. reqdstreg[ n ] is ignored when software handshaking is not enabled for the source of channel n . a channel dst_req bit is written only if the corresponding channel write enable bit in the req_we field is asserted on the same system bus write transfer. ? req_we[11:8]: request write enable 0 = write disabled 1 = write enabled ? dst_req[3:0]: destination request 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - req_we3 req_we2 req_we1 req_we0 76543210 - - - - dst_req3 dst_req2 dst_req1 dst_req0
371 32072d?04/2011 at32uc3a3/a4 19.12.18 single source transaction request register name: sglreqsrcreg access type: read/write offset: 0x378 reset value: 0x00000000 a bit is assigned for each channel in this register. sglreqsrcreg[ n ] is ignored when software handshaking is not enabled for the source of channel n . a channel s_sg_req bit is written only if the corresponding channel write enable bit in th e req_we field is asserted on the same system bus write transfer. ? req_we[11:8]: request write enable 0 = write disabled 1 = write enabled ? s_sg_req[3:0]: source single request 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - req_we3 req_we2 req_we1 req_we0 76543210 - - - - s_sg_req3 s_sg_re q2 s_sg_req1 s_sg_req0
372 32072d?04/2011 at32uc3a3/a4 19.12.19 single destination transaction request register name: sglreqdstreg access type: read/write offset: 0x380 reset value: 0x0000000 a bit is assigned for each channel in this register. sglreqdstreg[ n ] is ignored when software handshaking is not enabled for the source of channel n . a channel d_sg_req bit is written only if the corresponding channel write enable bit in the req_we field is asserted on the same system bus write transfer. ? req_we[11:8]: request write enable 0 = write disabled 1 = write enabled ? d_sg_req[3:0]: destin ation single request 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - req_we3 req_we2 req_we1 req_we0 76543210 - - - - d_sg_req3 d_sg_req2 d_sg_req1 d_sg_req0
373 32072d?04/2011 at32uc3a3/a4 19.12.20 last source transaction request register name: lstsrcreg access type: read/write offset: 0x388 reset value: 0x0000000 a bit is assigned for each channel in this register. lstsrcreg[ n ] is ignored when software handshaking is not enabled for the source of channel n . a channel lstsrc bit is written only if the corresponding c hannel write enable bit in the lstsrc_we field is asserted on the same system bus write transfer. ? lstsrc_we[11:8]: source last transaction request write enable 0 = write disabled 1 = write enabled ? lstsrc[3:0]: source last transaction request 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 ----lstsrc_w e3 lstsrc_w e2 lstsrc_w e1 lstsrc_w e0 76543210 - - - - lstsrc3 lstsrc2 lstsrc1 lstsrc0
374 32072d?04/2011 at32uc3a3/a4 19.12.21 last destination transaction request register name: lstdstreg access type: read/write offset: 0x390 reset value: 0x00000000 a bit is assigned for each channel in this register. lstdstreg[ n ] is ignored when software handshaking is not enabled for the source of channel n . a channel lstdst bit is written only if the corresponding channel write enable bit in the lstdst_we field is asserted on the same system bus write transfer. ? lstdst_we[11:8]: destination last transaction request write enable 0 = write disabled 1 = write enabled ? lstdst[3:0]: destination last transaction request 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - lstdst_we 3 lstdst_we 2 lstdst_we 1 lstdst_we 0 76543210 - - - - lstdst3 lstdst2 lstdst1 lstdst0
375 32072d?04/2011 at32uc3a3/a4 19.12.22 dma configuration register name: dmacfgreg access type: read/write offset: 0x398 reset value: 0x00000000 ? dma_en: dma controller enable 0 = dmaca disabled 1 = dmaca enabled. this register is used to enable the dmaca, which must be done before any channel activity can begin. if the global channel enable bit is clear ed while any channel is still active, then dm acfgreg.dma_en still returns ?1? to indi- cate that there are channels still active until hardware has terminated all activity on all channels, at which point the dmacfgreg.dma_en bit returns ?0?. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------dma_en
376 32072d?04/2011 at32uc3a3/a4 19.12.23 dma channel enable register name: chenreg access type: read/write offset: 0x3a0 reset value: 0x00000000 ? ch_en_we[11:8]: channel enable write enable the channel enable bit, ch_en, is only written if the corresponding channel writ e enable bit, ch_en_we, is asserted on the same system bus write transfer. for example, writing 0x101 writes a 1 into chenreg[0], while chenreg[7:1] remains unchanged. ? ch_en[3:0] 0 = disable the channel 1 = enable the channel enables/disables the channel. setting this bit enables a channel, clearing this bit disables the channel. the chenreg.ch_en bit is automatically cleared by hardware to disable the channel after the last system bus transfer of the dma transfer to the destination has completed.software ca n therefore poll this bit to determine when a dma transfer has completed. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 ----ch_en_we 3 ch_en_we 2 ch_en_we 1 ch_en_we 0 76543210 - - - - ch_en3 ch_en2 ch_en1 ch_en0
377 32072d?04/2011 at32uc3a3/a4 19.12.24 dmaca component id register low name: dmacompidregl access type: read-only offset: 0x3f8 reset value: 0x44571110 ? dma_comp_type designware component type number = 0x44571110. this assigned unique hex value is constant and is derived from the two ascii letters ?dw? followed by a 32-bit unsigned number 31 30 29 28 27 26 25 24 dma_comp_type[31:24] 23 22 21 20 19 18 17 16 dma_comp_type[23:16] 15 14 13 12 11 10 9 8 dma_comp_type[15:8] 76543210 dma_comp_type[7:0]
378 32072d?04/2011 at32uc3a3/a4 19.12.25 dmaca component id register high name: dmacompidregh access type: read-only offset: 0x3fc reset value: 0x3230362a ? dma_comp_version: version of the component 31 30 29 28 27 26 25 24 dma_comp_version[31:24] 23 22 21 20 19 18 17 16 dma_comp_version[23:16] 15 14 13 12 11 10 9 8 dma_comp_version[15:8] 76543210 dma_comp_version[7:0]
379 32072d?04/2011 at32uc3a3/a4 19.13 module configuration the following table defines the valid settings for the dest_per and src_per fields in the cfgxh register. the direction is specified as observed from the dmaca. so for instance, aes - rx means this hardware handshaking interface is connected to the input of the aes module l . table 19-6. dmaca handshake interfaces per value hardware handshaking interface 0 aes - rx 1 aes - tx 2 mci - rx 3mci -tx 4msi - rx 5msi - tx 6 dmaca - ext0 7 dmaca - ext1 table 19-7. dmaca external handshake signals handshaking interface function signal name dmaca - ext0 dma acknowledge (dmack0) dmaack[0] dma request (ndmareq0) dmarq[0] dmaca - ext1 dma acknowledge (dmack1) dmaack[1] dma request (ndmareq1) dmarq[1]
380 32072d?04/2011 at32uc3a3/a4 20. general-purpose input/ output controller (gpio) rev: 1.1.0.4 20.1 features each i/o line of the gpio features: ? configurable pin-change, rising-edge or falling-edge interrupt on any i/o line ? a glitch filter providing rejection of pulses shorter than one clock cycle ? input visibility and output control ? multiplexing of up to four peripheral functions per i/o line ? programmable internal pull-up resistor 20.2 overview the general purpose input/output controller manages the i/o pins of the microcontroller. each i/o line may be dedicated as a general-purpose i/o or be assigned to a function of an embedded peripheral. this assures effective optimization of the pins of a product. 20.3 block diagram figure 20-1. gpio block diagram 20.4 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. interrupt controller power manager embedded peripheral general purpose input/output - gpio gpio interrupt request clk_gpio pin control signals pin pin pin pin pin mcu i/o pins pb configuration interface
381 32072d?04/2011 at32uc3a3/a4 20.4.1 module configuration most of the features of the gpio are configurable for each product. the user must refer to the package and pinout chapter for these settings. product specific settings includes: ? number of i/o pins. ? functions implemented on each pin ? peripheral function(s) multiplexed on each i/o pin ? reset value of registers 20.4.2 clocks the clock for the gpio bus interface (clk_gpio) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. the clk_gpio must be enabled in order to access the configuration registers of the gpio or to use the gpio interrupts. after configuring the gp io, the clk_gpio can be disabled if interrupts are not used. 20.4.3 interrupts the gpio interrupt lines are connected to the interrupt controller. using the gpio interrupt requires the interrupt controller to be configured first. 20.5 functional description the gpio controls the i/o lines of the microcontroller. the control logic associated with each pin is represented in the figure below:
382 32072d?04/2011 at32uc3a3/a4 figure 20-2. overview of the gpio pad connections 20.5.1 basic operation 20.5.1.1 i/o line or peripheral function selection when a pin is multiplexed with one or more peri pheral functions, the selection is controlled with the gpio enable register (gper). if a bit in g per is written to one, the corresponding pin is controlled by the gpio. if a bit is written to zero , the corresponding pin is controlled by a periph- eral function. 20.5.1.2 peripheral selection the gpio provides multiplexing of up to four peripheral functions on a single pin. the selection is performed by accessing peripheral mux register 0 (pmr0) and peripheral mux register 1 (pmr1). 20.5.1.3 output control when the i/o line is assigned to a peripheral functi on, i.e. the corresponding bit in gper is writ- ten to zero, the drive of the i/o line is controlled by the peripheral. the peripheral, depending on the value in pmr0 and pmr1, determines whether the pin is driven or not. when the i/o line is controlled by the gpio, th e value of the output driver enable register (oder) determines if the pin is driven or not. when a bit in this register is written to one, the cor- 0 1 gper 1 0 ovr oder pmr1 periph. a output enable periph. b output enable periph. c output enable periph. d output enable periph. a output data periph. b output data periph. c output data periph. d output data pad puer periph. a input data periph. b input data periph. c input data periph. d input data pvr 0 1 glitch filter gfer edge detector 1 0 interrupt request imr1 pmr0 imr0 ier
383 32072d?04/2011 at32uc3a3/a4 responding i/o line is driven by the gpio. when the bit is written to zero, the gpio does not drive the line. the level driven on an i/o line can be determined by writing to the output value register (ovr). 20.5.1.4 inputs the level on each i/o line can be read through the pin value register (pvr). this register indi- cates the level of the i/o lines regardless of whether the lines are driven by the gpio or by an external component. note that due to power saving measures, the pvr register can only be read when gper is written to one for the corresponding pin or if interrupt is enabled for the pin. 20.5.1.5 output line timings the figure below shows the timing of the i/o line when writing a one and a zero to ovr. the same timing applies when performing a ?set? or ?clear? access, i.e., writing a one to the output value set register (ovrs) or the output val ue clear register (ovrc). the timing of pvr is also shown. figure 20-3. output line timings 20.5.2 advanced operation 20.5.2.1 pull-up resistor control each i/o line is designed with an embedded pull-up resistor. the pull-up resistor can be enabled or disabled by writing a one or a zero to t he corresponding bit in the pull-up enable register (puer). control of the pull-up resistor is possi ble whether an i/o line is controlled by a periph- eral or the gpio. 20.5.2.2 input glitch filter optional input glitch filters can be enabled on each i/o line. when the glitch filter is enabled, a glitch with duration of less than 1 clock cycle is automatically rejected, while a pulse with dura- tion of 2 clock cycles or more is accepted. for pulse durations between 1 clock cycle and 2 clock cycles, the pulse may or may not be taken into account, depending on the precise timing of its occurrence. thus for a pulse to be guaranteed visible it must exceed 2 clock cycles, whereas for a glitch to be reliably filtered out, its duration must not exceed 1 clock cycle. the filter introduces 2 clock cycles of latency. the glitch filters are controlled by the glitch filter enable register (gfer). when a bit is written to one in gfer, the glitch filter on the corresponding pin is enabled. the glitch filter affects only interrupt inputs. inputs to peripherals or the value read through pvr are not affected by the glitch filters. pb access pb access clk_gpio write ovr to 1 write ovr to 0 ovr / i/o line pvr
384 32072d?04/2011 at32uc3a3/a4 20.5.3 interrupts the gpio can be configured to generate an interrupt when it detects an input change on an i/o line. the module can be configured to signal an interrupt whenever a pin changes value or only to trigger on rising edges or fa lling edges. interrupts are enabled on a pin by writing a one to the corresponding bit in the interrupt enable register (ier). the interrupt mode is set by writing to the interrupt mode register 0 (imr0) and the interrupt mode register 1(imr1). interrupts can be enabled on a pin, regardless of the configuration of the i/o line, i.e. whether it is controlled by the gpio or assigned to a peripheral function. in every port there are four interrupt lines connected to the interrupt controller. groups of eight interrupts in the port are ored together to form an interrupt line. when an interrupt event is detected on an i/o line, and the corresponding bit in ier is written to one, the gpio interrupt request line is asserted. a number of interrupt signals are ored-wired together to generate a single interrupt signal to the interrupt controller. the interrupt flag register (ifr) can by read to determine which pin(s) caused the interrupt. the interrupt bit must be cleared by writing a one to the interrupt flag clear register (ifrc). to take effect, the clear operation must be perform ed when the interrupt line is enabled in ier. oth- erwise, it will be ignored. gpio interrupts can only be triggered when the clk_gpio is enabled. 20.5.4 interrupt timings the figure below shows the timing for rising edge (or pin-change) interrupts when the glitch filter is disabled. for the pulse to be registered, it mu st be sampled at the rising edge of the clock. in this example, this is not the case for the first pulse. the second pulse is however sampled on a rising edge and will trigge r an interr upt request. figure 20-4. interrupt timing with glitch filter disabled the figure below shows the timing for rising edge (or pin-change) interrupts when the glitch filter is enabled. for the pulse to be registered, it must be sampled on two subsequent rising edges. in the example, the first pulse is rejected while the second pulse is accepted and causes an interrupt request. figure 20-5. interrupt timing with glitch filter enabled clock pin level gpio_ifr clock pin level gpio_ifr
385 32072d?04/2011 at32uc3a3/a4 20.6 user interface the gpio controls all the i/o pins on the avr32 microcontroller. the pins are managed as 32- bit ports that are configurable through a pb interface. each port has a set of configuration regis- ters. the overall memory map of the gpio is shown below. the number of pins and hence the number of ports are product specific. figure 20-6. overall mermory map in the gpio controller function multiplexingtable in the package and pinout chapter, each gpio line has a unique number. note that the pa, pb, pc and px ports do not directly corre- spond to the gpio ports. to find the corresponding port and pin the following formula can be used: gpio port = floor((gpio number) / 32), example: floor((36)/32) = 1 gpio pin = gpio number mod 32, example: 36 mod 32 = 4 the table below shows the configuration registers for one port. addresses shown are relative to the port address offset. the specific address of a configuration register is found by adding the port 0 configuration registers port 1 configuration registers port 2 configuration registers port 3 configuration registers port 4 configuration registers 0x0000 0x0100 0x0200 0x0300 0x0400
386 32072d?04/2011 at32uc3a3/a4 register offset and the port offset to the gpio start address. one bit in each of the configuration registers corresponds to an i/o pin. table 20-1. gpio register memory map offset register function name access reset value 0x00 gpio enable register read/write gper read/write (1) 0x04 gpio enable register set gpers write-only 0x08 gpio enable register clear gperc write-only 0x0c gpio enable register toggle gpert write-only 0x10 peripheral mux register 0 read/write pmr0 read/write (1) 0x14 peripheral mux register 0 set pmr0s write-only 0x18 peripheral mux register 0 clear pmr0c write-only 0x1c peripheral mux register 0 to g g l e pmr0t write-only 0x20 peripheral mux register 1 read/write pmr1 read/write (1) 0x24 peripheral mux register 1 set pmr1s write-only 0x28 peripheral mux register 1 clear pmr1c write-only 0x2c peripheral mux register 1 toggle pmr1t write-only 0x40 output driver enable register read/write oder read/write (1) 0x44 output driver enable register set oders write-only 0x48 output driver enable register clear oderc write-only 0x4c output driver enable register toggle odert write-only 0x50 output value register read/write ovr read/write (1) 0x54 output value register set ovrs write-only 0x58 output value register clear ovrc write-only 0x5c output value register to g g l e ovrt write-only 0x60 pin value register read pvr read-only (2) 0x70 pull-up enable register read/write puer read/write (1) 0x74 pull-up enable register set puers write-only 0x78 pull-up enable register clear puerc write-only 0x7c pull-up enable register to g g l e puert write-only 0x90 interrupt enable register read/write ier read/write (1) 0x94 interrupt enable register set iers write-only 0x98 interrupt enable register clear ierc write-only 0x9c interrupt enable register to g g l e iert write-only 0xa0 interrupt mode register 0 read/write imr0 read/write (1) 0xa4 interrupt mode register 0 set imr0s write-only 0xa8 interrupt mode register 0 clear imr0c write-only 0xac interrupt mode register 0 toggle imr0t write-only 0xb0 interrupt mode register 1 read/write imr1 read/write (1)
387 32072d?04/2011 at32uc3a3/a4 1) the reset value for these registers are device specific. please refer to the module config- uration section at the end of this chapter. 2) the reset value is undefined depending on the pin states. 20.6.1 access types each configuration register can be accessed in four different ways. the first address location can be used to write the register directly. this address can also be used to read the register value. the following addresses fac ilitate three different types of wr ite access to th e register. per- forming a ?set? access, all bits written to one will be set. bits written to ze ro will be unchanged by the operation. performing a ?clear? access, all bits written to one will be cleared. bits written to zero will be unchanged by the o peration. finally, a toggle access will toggle the value of all bits written to one. again all bits written to zero remain unchanged. note that for some registers (e.g. ifr), not all access methods are permitted. note that for ports with less than 32 bits, the corresponding control registers will have unused bits. this is also the case for features that are not implemented for a specific pin. writing to an unused bit will have no effect. reading unused bits will always return 0. 0xb4 interrupt mode register 1 set imr1s write-only 0xb8 interrupt mode register 1 clear imr1c write-only 0xbc interrupt mode register 1 to g g l e imr1t write-only 0xc0 glitch filter enable regi ster read/write gfer read/write (1) 0xc4 glitch filter enable register set gfers write-only 0xc8 glitch filter enable r egister clear gferc write-only 0xcc glitch filter enable register toggle gfert write-only 0xd0 interrupt flag register read ifr read-only (1) 0xd4 interrupt flag register - - - 0xd8 interrupt flag register clear ifrc write-only 0xdc interrupt flag register - - - table 20-1. gpio register memory map offset register function name access reset value
388 32072d?04/2011 at32uc3a3/a4 20.6.2 enable register name: gper access type: read, write, set, clear, toggle offset : 0x00, 0x04, 0x08, 0x0c reset value: - ? p0-p31: pin enable 0: a peripheral function controls the corresponding pin. 1: the gpio controls the corresponding pin. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
389 32072d?04/2011 at32uc3a3/a4 20.6.3 peripheral mux register 0 name: pmr0 access type: read, write, set, clear, toggle offset : 0x10, 0x14, 0x18, 0x1c reset value: - ? p0-31: peripheral mult iplexer select bit 0 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
390 32072d?04/2011 at32uc3a3/a4 20.6.4 peripheral mux register 1 name: pmr1 access type: read, write, set, clear, toggle offset : 0x20, 0x24, 0x28, 0x2c reset value: - ? p0-31: peripheral mult iplexer select bit 1 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0 {pmr1, pmr0} selected peripheral function 00 a 01 b 10 c 11 d
391 32072d?04/2011 at32uc3a3/a4 20.6.5 output driver enable register name: oder access type: read, write, set, clear, toggle offset : 0x40, 0x44, 0x48, 0x4c reset value: - ? p0-31: output driver enable 0: the output driver is disabled for the corresponding pin. 1: the output driver is enabled for the corresponding pin. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
392 32072d?04/2011 at32uc3a3/a4 20.6.6 output value register name: ovr access type: read, write, set, clear, toggle offset : 0x50, 0x54, 0x58, 0x5c reset value: - ? p0-31: output value 0: the value to be driven on the i/o line is 0. 1: the value to be driven on the i/o line is 1. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
393 32072d?04/2011 at32uc3a3/a4 20.6.7 pin value register name: pvr access type: read offset : 0x60, 0x64, 0x68, 0x6c reset value: - ? p0-31: pin value 0: the i/o line is at level ?0?. 1: the i/o line is at level ?1?. note that the level of a pin can only be read when gper is set or interrupt is enabled for the pin. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
394 32072d?04/2011 at32uc3a3/a4 20.6.8 pull-up enable register name: puer access type: read, write, set, clear, toggle offset : 0x70, 0x74, 0x78, 0x7c reset value: - ? p0-31: pull-up enable 0: the internal pull-up resistor is disabled for the corresponding pin. 1: the internal pull-up resistor is enabled for the corresponding pin. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
395 32072d?04/2011 at32uc3a3/a4 20.6.9 interrupt enable register name: ier access type: read, write, set, clear, toggle offset : 0x90, 0x94, 0x98, 0x9c reset value: - ? p0-31: interrupt enable 0: interrupt is disabled for the corresponding pin. 1: interrupt is enabled for the corresponding pin. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
396 32072d?04/2011 at32uc3a3/a4 20.6.10 interrupt mode register 0 name: imr0 access type: read, write, set, clear, toggle offset : 0xa0, 0xa4, 0xa8, 0xac reset value: - ? p0-31: interrupt mode bit 0 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
397 32072d?04/2011 at32uc3a3/a4 20.6.11 interrupt mode register 1 name: imr1 access type: read, write, set, clear, toggle offset : 0xb0, 0xb4, 0xb8, 0xbc reset value: - ? p0-31: interrupt mode bit 1 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0 {imr1, imr0} interrupt mode 00 pin change 01 rising edge 10 falling edge 11 reserved
398 32072d?04/2011 at32uc3a3/a4 20.6.12 glitch filter enable register name: gfer access type: read, write, set, clear, toggle offset : 0xc0, 0xc4, 0xc8, 0xcc reset value: - ? p0-31: glitch filter enable 0: glitch filter is disabled for the corresponding pin. 1: glitch filter is enabled for the corresponding pin. note! the value of this register should only be changed wh en ier is ?0?. updating this gfer while interrupt on the corresponding pin is enabled can cause an unintentional interrupt to be triggered. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
399 32072d?04/2011 at32uc3a3/a4 20.6.13 interrupt flag register name: ifr access type: read, clear offset : 0xd0, 0xd8 reset value: - ? p0-31: interrupt flag 1: an interrupt condition has been detected on the corresponding pin. 0: no interrupt condition has beedn detected on the corres ponding pin since reset or the last time it was cleared. the number of interrupt request lines is dependant on the number of i/o pins on the mcu. refer to the product specific data for details. note also that a bit in the interrupt flag register is only valid if the corresponding bit in ier is set. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
400 32072d?04/2011 at32uc3a3/a4 20.7 programming examples 20.7.1 8-bit led-chaser // set r0 to gpio base address mov r0, lo(avr32_gpio_address) orh r0, hi(avr32_gpio_address) // enable gpio control of pin 0-8 mov r1, 0xff st.w r0[avr32_gpio_gpers], r1 // set initial value of port mov r2, 0x01 st.w r0[avr32_gpio_ovrs], r2 // set up toggle value. two pins are toggled // in each round. the bit that is currently set, // and the next bit to be set. mov r2, 0x0303 orh r2, 0x0303 loop: // only change 8 lsb mov r3, 0x00ff and r3, r2 st.w r0[avr32_gpio_ovrt], r3 rol r2 rcall delay rjmp loop it is assumed in this example that a subroutine "delay" exists that returns after a given time. 20.7.2 configuration of usart pins the example below shows how to configure a peripheral module to control i/o pins. it assumed in this example that the usart receive pin (rxd) is connected to pc16 and that the usart transmit pin (txd) is connected to pc17. for both pins, the usart is peripheral b. in this example, the state of the gpio registers is assumed to be unknown. the two usart pins are therefore first set to be controlled by the gpio wit h output drivers disabled. the pins can then be assured to be tri-stated while changing the peripheral mux registers. // set up pointer to gpio, portc mov r0, lo(avr32_gpio_address + portc_offset) orh r0, hi(avr32_gpio_address + portc_offset) // disable output drivers
401 32072d?04/2011 at32uc3a3/a4 mov r1, 0x0000 orh r1, 0x0003 st.w r0[avr32_gpio_oderc], r1 // make the gpio control the pins st.w r0[avr32_gpio_gpers], r1 // select peripheral b on pc16-pc17 st.w r0[avr32_gpio_pmr0s], r1 st.w r0[avr32_gpio_pmr1c], r1 // enable peripheral control st.w r0[avr32_gpio_gperc], r1
402 32072d?04/2011 at32uc3a3/a4 20.8 module configuration the specific configuration for each gpio instance is listed in the following tables.the module bus clocks listed here are connected to the system bus clocks according to the table in the sys- tem bus clock connections section. the reset values for all gpio registers are zero with the following exceptions: table 20-2. module configuration feature gpio number of gpio ports 4 number of peripheral functions 4 table 20-3. module clock name module name clock name gpio clk_gpio table 20-4. register reset values port register reset value 0 gper 0xffffffff 0 gfer 0xffffffff 1 gper 0xffffffff 1 gfer 0xffffffff 2 gper 0xffffffff 2 gfer 0xffffffff 3 gper 0x00007fff 3 gfer 0x00007fff
403 32072d?04/2011 at32uc3a3/a4 21. serial peripheral interface (spi) rev: 2.1.0.3 21.1 features ? compatible with an embedded 32-bit microcontroller ? supports communication with serial external devices ? four chip selects with extern al decoder support allow co mmunication with up to 15 peripherals ? serial memories, such as da taflash and 3-wire eeproms ? serial peripherals, such as adcs, dacs, l cd controllers, can controllers and sensors ? external co-processors ? master or slave serial peripheral bus interface ? 4 - to 16-bit programmable da ta length per chip select ? programmable phase and polarity per chip select ? programmable transfer delays between consecutive transfers and between clock and data per chip select ? programmable delay between consecutive transfers ? selectable mode fault detection ? connection to peripheral dma controller ch annel capabilities opti mizes data transfers ? one channel for the receiver, one channel for the transmitter ? next buffer support ? four character fifo in reception 21.2 overview the serial peripheral interface (spi) circuit is a synchronous serial data link that provides com- munication with external devices in master or slave mode. it also enables communication between processors if an external processor is connected to the system. the serial peripheral interface is essentially a shift register that serially transmits data bits to other spis. during a data transfer, one spi syste m acts as the ?master?' which controls the data flow, while the other devices act as ?slaves'' whic h have data shifted into and out by the master. different cpus can take turn being masters (multiple master protocol opposite to single master protocol where one cpu is always the master while all of the others are always slaves) and one master may simultaneously shift da ta into multiple slaves. howeve r, only one slave may drive its output to write data back to the master at any given time. a slave device is selected when the master asse rts its nss signal. if multiple slave devices exist, the master generates a separate slav e select signal for each slave (npcs). the spi system consists of two data lines and two control lines: ? master out slave in (mosi): this data line supplies the output data from the master shifted into the input(s) of the slave(s). ? master in slave out (miso): this data line supplies the output data from a slave to the input of the master. there may be no more than one slave transmitting data during any particular transfer. ? serial clock (spck): this contro l line is driven by the master and regulates the flow of the data bits. the master may transmit data at a variety of baud rates; the spck line cycles once for each bit that is transmitted. ? slave select (nss): this control line allows slaves to be turned on and off by hardware.
404 32072d?04/2011 at32uc3a3/a4 21.3 block diagram figure 21-1. spi block diagram 21.4 application block diagram figure 21-2. application block diagram: single master/multiple slave implementation spi interface interrupt control peripheral dma controller i/o controller clk_spi peripheral bus spi interrupt spck npcs3 npcs2 npcs1 npcs0/nss mosi miso slave 0 slave 2 slave 1 spck npcs3 npcs2 npcs1 npcs0 mosi miso spi master spck nss mosi miso spck nss mosi miso spck nss mosi miso nc
405 32072d?04/2011 at32uc3a3/a4 21.5 i/o lines description 21.6 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 21.6.1 i/o lines the pins used for interfacing the compliant external devices may be multiplexed with i/o lines. the user must first configure the i/o controll er to assign the spi pins to their peripheral functions. 21.6.2 clocks the clock for the spi bus interface (clk_spi) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to disable the spi before disabling the clock, to avoid freezing the spi in an undefined state. 21.6.3 interrupts the spi interrupt request line is connected to the interrupt controller. using the spi interrupt requires the interrupt controller to be programmed first. 21.7 functional description 21.7.1 modes of operation the spi operates in master mode or in slave mode. operation in master mode is configured by writing a one to the master/slave mode bit in the mode register (mr.mstr). the pins npcs0 to npcs3 are all configured as outputs, the spck pin is driven, the miso line is wired on the rece iver input and the mosi line driven as an output by the transmitter. if the mr.mstr bit is written to zero, the spi ope rates in slave mode. the miso line is driven by the transmitter output, the mosi line is wired on the receiver input, the spck pin is driven by the transmitter to synchronize the receiver. the npcs0 pin becomes an input, and is used as a slave select signal (nss). the pins npcs1 to npcs3 are not driven and can be used for other purposes. the data transfers are identically programmable for both modes of operations. the baud rate generator is activated only in master mode. table 21-1. i/o lines description pin name pin description type master slave miso master in slave out input output mosi master out slave in output input spck serial clock output input npcs1-npcs3 peripheral chip selects output unused npcs0/nss peripheral chip select/slave select output input
406 32072d?04/2011 at32uc3a3/a4 21.7.2 data transfer four combinations of polarity and phase are available for data transfers. the clock polarity is configured with the clock polarity bit in the chip select registers (csrn.cpol). the clock phase is configured with the clock phase bit in the csrn registers (csrn.ncpha). these two bits determine the edges of the clock signal on which data is driven and sampled. each of the two bits has two possible states, resulting in four possible combinations that are incompatible with one another. thus, a master/slave pair must use the same parameter pair values to com- municate. if multiple slaves are used and fix ed in different configurations, the master must reconfigure itself each time it needs to communicate with a different slave. table 21-2 on page 406 shows the four modes and corresponding parameter settings. figure 21-3 on page 406 and figure 21-4 on page 407 show examples of data transfers. figure 21-3. spi transfer format (ncpha = 1, 8 bits per transfer) table 21-2. spi modes spi mode cpol ncpha 001 100 211 310 14 3 2 58 7 6 spck cycle (for reference) spck (cpol = 0) nss (to slave) miso (from slave) mosi (from master) spck (cpol = 1) msb 6 4 5lsb 1 2 3 msb 6 *** lsb 1 2 3 4 5 *** not defined, but normaly msb of previous character received
407 32072d?04/2011 at32uc3a3/a4 figure 21-4. spi transfer format (ncpha = 0, 8 bits per transfer) 21.7.3 master mode operations when configured in master mode, the spi uses the internal programmable baud rate generator as clock source. it fully controls the data transfers to and from the slave(s) connected to the spi bus. the spi drives the chip select line to the slave and the serial clock signal (spck). the spi features two holding registers, the tr ansmit data register (tdr) and the receive data register (rdr), and a single shi ft register. the holding registers maintain the data flow at a constant rate. after enabling the spi, a data transfer begins when the processor writes to the tdr register. the written data is immediately transferred in the shift register and transfer on the spi bus starts. while the data in the shift register is shifted on the mosi line, the miso line is sampled and shifted in the shift register. transmission cannot occur without reception. before writing to the tdr, the peripheral chip select field in tdr (tdr.pcs) must be written in order to select a slave. if new data is written to tdr during the transfer, it stays in it until the current transfer is com- pleted. then, the received data is transferred from the shift register to rdr, the data in tdr is loaded in the shift register and a new transfer starts. the transfer of a data written in tdr in the shift register is indicated by the transmit data reg- ister empty bit in the status register (sr.tdre). when new data is written in tdr, this bit is cleared. the sr.tdre bit is used to trigger the transmit peripheral dma controller channel. the end of transfer is indicated by the transmission registers empty bit in the sr register (sr.txempty). if a transfer delay (csrn.dlybct) is greater than zero for the last transfer, sr.txempty is set after the completion of said delay. the clk_spi can be switched off at this time. during reception, received data are transferred from the shift register to the reception fifo. the fifo can contain up to 4 characters (both receive data and peripheral chip select fields). while a character of the fifo is unread, the receive data register full bit in sr remains high (sr.rdrf). characters are read through the rdr re gister. if the four char acters stored in the fifo are not read and if a new character is stored, this sets the overrun error status bit in the sr register (sr.ovres). the procedure to follow in such a case is described in section 21.7.3.8 . 14 3 2 58 7 6 spck cycle (for reference) spck (cpol = 0) nss (to slave) miso (from slave) mosi (from master) spck (cpol = 1) msb 6 4 5lsb 1 2 3 6 lsb 1 2 3 4 5 *** not defined, but normaly lsb of previous character transmitted msb ***
408 32072d?04/2011 at32uc3a3/a4 in master mode, if the received data is not read fast enough compared to the transfer rhythm imposed by the write accesses in the tdr, some overrun errors may occur, even if the fifo is enabled. to insure a perfect data integrity of received data (especially at high data rate), the mode wait data read before transfer can be enabled in the mr register (mr.wdrbt). when this mode is activated, no transfer starts while received data remains unread in the rdr. when data is written to the tdr and if unread received data is stored in the rdr, the transfer is paused until the rdr is read. in this mode no ov errun error can occur. please note that if this mode is enabled, it is useless to activate the fifo in reception. figure 21-5 on page 408 shows a block diagram of the spi when operating in master mode. fig- ure 21-6 on page 409 shows a flow chart describing how transfers are handled. 21.7.3.1 master mode block diagram figure 21-5. master mode block diagram baud rate generator rxfifoen 4 ? character fifo shift register tdre rxfifoen 4 ? character fifo ps pcsdec current peripheral modf modfdis mstr scbr csr0..3 csr0..3 cpol ncpha bits rdr rd rdrf ovres td tdr rdr csaat csnaat csr0..3 pcs mr pcs tdr spck clk_spi miso mosi msb lsb npcs1 npcs2 npcs3 npcs0 spi clock 0 1 0 1 0 1 npcs0
409 32072d?04/2011 at32uc3a3/a4 21.7.3.2 master mode flow diagram figure 21-6. master mode flow diagram spi enable csaat ? ps ? 1 0 0 1 1 npcs = tdr(pcs) npcs = mr(pcs) delay dlybs serializer = tdr(td) tdre = 1 data transfer rdr(rd) = serializer rdrf = 1 tdre ? npcs = 0xf delay dlybcs fixed peripheral variable peripheral delay dlybct 0 1 csaat ? 0 tdre ? 1 0 ps ? 0 1 tdr(pcs) = npcs ? no yes mr(pcs) = npcs ? no npcs = 0xf delay dlybcs npcs = tdr(pcs) npcs = 0xf delay dlybcs npcs = mr(pcs), tdr(pcs) fixed peripheral variable peripheral - npcs defines the current chip select - csaat, dlybs, dlybct refer to the fields of the chip select register corresponding to the current chip select - when npcs is 0xf, csaat is 0.
410 32072d?04/2011 at32uc3a3/a4 21.7.3.3 clock generation the spi baud rate clock is generated by dividing the clk_spi , by a value between 1 and 255. this allows a maximum operating baud rate at up to clk_spi and a minimum operating baud rate of clk_spi divided by 255. writing the serial clock baud rate field in the csrn registers (csrn.scbr) to zero is forbid- den. triggering a transfer while csrn.scbr is zero can lead to unpredictable results. at reset, csrn.scbr is zero and the user has to configure it at a valid value before performing the first transfer. the divisor can be defined independently for each chip select, as it has to be configured in the csrn.scbr field. this allows the spi to au tomatically adapt the baud rate for each interfaced peripheral without reprogramming. 21.7.3.4 transfer delays figure 21-7 on page 410 shows a chip select transfer change and consecutive transfers on the same chip select. three delays can be configured to modify the transfer waveforms: ? the delay between chip selects, programmable only once for all the chip selects by writing to the delay between chip selects field in the mr register (mr. dlybcs). allows insertion of a delay between release of one chip select and before assertion of a new one. ? the delay before spck, independently programmable for each chip select by writing the delay before spck field in the csrn register s (csrn.dlybs). allows the start of spck to be delayed after the chip select has been asserted. ? the delay between consecutive transfers, independently programmable for each chip select by writing the delay between consecutive transfers field in the csrn registers (csrn.dlybct). allows insertion of a delay be tween two transfers occurring on the same chip select these delays allow the spi to be adapted to the interfaced peripherals and their speed and bus release time. figure 21-7. programmable delays dlybcs dlybs dlybct dlybct chip select 1 chip select 2 spck
411 32072d?04/2011 at32uc3a3/a4 21.7.3.5 peripheral selection the serial peripherals are selected through the assertion of the npcs0 to npcs3 signals. by default, all the npcs signals are high before and after each transfer. the peripheral selection can be performed in two different ways: ? fixed peripheral select: spi exchanges data with only one peripheral ? variable peripheral select: data can be exchanged with more than one peripheral fixed peripheral select is activated by writing a ze ro to the peripheral select bit in mr (mr.ps). in this case, the current peripheral is defined by the mr.pcs field and the tdr.pcs field has no effect. variable peripheral select is activated by writing a one to the mr.ps bit . the tdr.pcs field is used to select the current peripheral. this means that the peripheral selection can be defined for each new data. the fixed peripheral selection allows buffer transfers with a single peripheral. using the periph- eral dma controller is an optimal means, as the size of the data transfer between the memory and the spi is either 4 bits or 16 bits. however, changing the peripheral selection requires the mode register to be reprogrammed. the variable peripheral selection allows buffer transfers with multiple peripherals without repro- gramming the mr register. data written to tdr is 32-bits wide and defines the real data to be transmitted and the peripheral it is destined to. using the peripheral dma controller in this mode requires 32-bit wide buffers, with the data in the lsbs and the pcs and lastxfer fields in the msbs, however the spi still controls the number of bits (8 to16) to be transferr ed through miso and mosi lines with the csrn registers. this is not the optimal means in term of memory size for the buffers, but it provides a very effective means to exchange data with several peripherals without any intervention of the processor. 21.7.3.6 peripheral chip select decoding the user can configure the spi to operate with up to 15 peripherals by decoding the four chip select lines, npcs0 to npcs3 with an external logic. this can be enabled by writing a one to the chip select decode bit in the mr register (mr.pcsdec). when operating without decoding, the spi makes sure that in any case only one chip select line is activated, i.e. driven low at a time. if two bits are defined low in a pcs field, only the lowest numbered chip select is driven low. when operating with decoding, the spi directly outputs the value defined by the pcs field of either the mr register or the tdr register (depending on ps). as the spi sets a default value of 0xf on the chip select lines (i.e. all chip select lines at one) when not processing any transfer, only 15 peripherals can be decoded. the spi has only four chip select registers, not 15. as a result, when decoding is activated, each chip select defines the characteristics of up to four peripherals. as an example, the crs0 register defines the characteristics of the exter nally decoded peripherals 0 to 3, corresponding to the pcs values 0x0 to 0x3. thus, the user has to make sure to connect compatible peripherals on the decoded chip select lines 0 to 3, 4 to 7, 8 to 11 and 12 to 14. 21.7.3.7 peripheral deselection when operating normally, as soon as the transfer of the last data written in tdr is completed, the npcs lines all rise. this might lead to runtime error if the processor is too long in responding
412 32072d?04/2011 at32uc3a3/a4 to an interrupt, and thus might lead to difficulties for interfacing with some serial peripherals requiring the chip select li ne to remain active during a full set of transfers. to facilitate interfacing with such devices, the csrn registers can be configur ed with the chip select active after transfer bit written to one (csrn.csaat) . this allows the chip select lines to remain in their current state (low = active) until transfer to another peripheral is required. when the csrn.csaat bit is written to qero, the npcs does not rise in all cases between two transfers on the same peripheral. during a transfe r on a chip select, the sr.tdre bit rises as soon as the content of the tdr is transferred into the internal shifter. when this bit is detected the tdr can be reloaded. if this reload occurs before the end of the current transfer and if the next transfer is performed on the same chip select as the current transfer, the chip select is not de-asserted between the two transfers. this migh t lead to difficulties fo r interfacing with some serial peripherals requiring the chip select to be de-asserted after each transfer. to facilitate interfacing with such devices, the csrn register s can be configured with the chip select not active after transfer bit (csrn.csnaat) written to one. this allows to de-assert systematically the chip select lines during a time dlybcs. (the value of th e csrn.csnaat bit is taken into account only if the csrn.csaat bit is written to zero for the same chip select). figure 21-8 on page 413 shows different peripheral deselection cases and the effect of the csrn.csaat and csrn.csnaat bits. 21.7.3.8 fifo management a fifo has been implemented in reception fifo (both in master and in slave mode), in order to be able to store up to 4 characters without causing an overrun error. if an attempt is made to store a fifth character, an overrun error rises. if such an event occurs, the fifo must be flushed. there are two ways to flush the fifo: ? by performing four read accesses of the rdr (the data read must be ignored) ? by writing a one to the flush fifo command bit in the cr register (cr.flushfifo). after that, the spi is able to receive new data.
413 32072d?04/2011 at32uc3a3/a4 figure 21-8. peripheral deselection figure 21-8 on page 413 shows different peripheral deselection cases and the effect of the csrn.csaat and csrn.csnaat bits. 21.7.3.9 mode fault detection the spi is capable of detecting a mode fault when it is configured in master mode and npcs0, mosi, miso, and spck are configured as open dr ain through the i/o controller with either internal or external pullup resistors. if t he i/o controller does not have open-drain capability, mode fault detection must be disabled by writing a one to the mode fault detection bit in the mr a npcs[0..3] write tdr tdre npcs[0..3] write tdr tdre npcs[0..3] write tdr tdre dlybcs pcs = a dlybcs dlybct a pcs = b b dlybcs pcs = a dlybcs dlybct a pcs = b b dlybcs dlybct pcs=a a dlybcs dlybct a pcs = a a a dlybct aa csaat = 0 and csnaat = 0 dlybct aa csaat = 1 and csnaat= 0 / 1 a dlybcs pcs = a dlybct aa csaat = 0 and csnaat = 1 npcs[0..3] write tdr tdre pcs = a dlybct aa csaat = 0 and csnaat = 0
414 32072d?04/2011 at32uc3a3/a4 register (mr.modfdis). in systems with open-drain i/o lines, a mode fault is detected when a low level is driven by an external master on the npcs0/nss signal. when a mode fault is detected, the mode fault error bit in the sr (sr.modf) is set until the sr is read and the spi is automatically disabled until re-enabled by writing a one to the spi enable bit in the cr register (cr.spien). by default, the mode fault detection circuitry is enabled. the user can disable mode fault detec- tion by writing a one to the mode fault dete ction bit in the mr re gister (mr.modfdis). 21.7.4 spi slave mode when operating in slave mode, the spi processes data bits on the clock provided on the spi clock pin (spck). the spi waits for nss to go active before receiving the serial clock from an external master. when nss falls, the clock is validated on the serializer, which processes the number of bits defined by the bits per transfer field of the chip select register 0 (csr0.bits). these bits are processed following a phase and a polarity defined respectively by the csr0.ncpha and csr0.cpol bits. note that the bits, cpol, and ncp ha bits of the other chip select registers have no effect when the spi is configured in slave mode. the bits are shifted out on the miso line and sampled on the mosi line. when all the bits are processed, the received data is transferred in the receive data register and the sr.rdrf bit rises. if the rdr register has not been read before new data is received, the sr.ovres bit is set. data is loaded in rdr even if this flag is set. th e user has to read the sr register to clear the sr.ovres bit. when a transfer starts, the data shifted out is the data present in the shift register. if no data has been written in the tdr register, the last data received is transferred. if no data has been received since the last reset, all bits are transmi tted low, as the shift register resets to zero. when a first data is written in tdr, it is trans ferred immediately in the shift register and the sr.tdre bit rises. if new data is written, it rema ins in tdr until a transfer occurs, i.e. nss falls and there is a valid clock on the spck pin. w hen the transfer occurs, the last data written in tdr is transferred in the shift register and the sr.tdre bit rises. this enables frequent updates of critical variables with single transfers. then, a new data is loaded in the shift register from the tdr. in case no character is ready to be transmitted, i.e. no character has been written in tdr since the last load from tdr to the shift register, the shift register is not modified and the last received character is retransmitted. in this case the underrun error status bit is set in sr (sr.undes). figure 21-9 on page 415 shows a block diagram of the spi when operating in slave mode.
415 32072d?04/2011 at32uc3a3/a4 figure 21-9. slave mode functional block diagram shift register spck spiens lsb msb nss mosi spi clock tdre tdr td rdrf ovres csr0 cpol ncpha bits spien spidis miso undes rdr rd 4 - character fifo 0 1 rxfifoen
416 32072d?04/2011 at32uc3a3/a4 21.8 user interface note: 1. the reset values are device specific. please refer to the module configuration section at the end of this chapter. table 21-3. spi register memory map offset register register name access reset 0x00 control register cr write-only 0x00000000 0x04 mode register mr read/write 0x00000000 0x08 receive data register rdr read-only 0x00000000 0x0c transmit data register tdr write-only 0x00000000 0x10 status register sr read-only 0x00000000 0x14 interrupt enable register ier write-only 0x00000000 0x18 interrupt disable register idr write-only 0x00000000 0x1c interrupt mask register imr read-only 0x00000000 0x30 chip select register 0 csr0 read/write 0x00000000 0x34 chip select register 1 csr1 read/write 0x00000000 0x38 chip select register 2 csr2 read/write 0x00000000 0x3c chip select register 3 csr3 read/write 0x00000000 0x e4 write protection control register wpcr read/write 0x00000000 0xe8 write protection status register wpsr read-only 0x00000000 0xfc version register version read-only - (1)
417 32072d?04/2011 at32uc3a3/a4 21.8.1 control register name: cr access type: write-only offset: 0x00 reset value: 0x00000000 ? lastxfer: last transfer 1: the current npcs will be deasserted after the character wr itten in td has been transferred. when csrn.csaat is one, this allows to close the communication with the current serial peri pheral by raising the corresponding npcs line as soon as td transfer has completed. 0: writing a zero to this bit has no effect. ? flushfifo: flush fifo command 1: if the fifo mode is enabled (mr.fifoen written to one) and if an overrun error has been detected, this command allows to empty the fifo. 0: writing a zero to this bit has no effect. ? swrst: spi software reset 1: writing a one to this bit will reset the spi. a software-trigger ed hardware reset of the spi interface is performed. the spi is in slave mode after software reset. peripheral dma controller channels are not affected by software reset. 0: writing a zero to this bit has no effect. ? spidis: spi disable 1: writing a one to this bit will disable the spi. as soon as spi dis is written to one, the spi finishes its transfer, all pins are set in input mode and no data is received or transmitted. if a transfe r is in progress, the transfer is finished before the spi is disabled. if both spien and spidis are equal to one when the cr register is written, the spi is disabled. 0: writing a zero to this bit has no effect. ? spien: spi enable 1: writing a one to this bit will enable the spi to transfer and receive data. 0: writing a zero to this bit has no effect. 31 30 29 28 27 26 25 24 -------lastxfer 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------flushfifo 76543210 swrst - - - - - spidis spien
418 32072d?04/2011 at32uc3a3/a4 21.8.2 mode register name: mr access type: read/write offset: 0x04 reset value: 0x00000000 ? dlybcs: delay between chip selects this field defines the delay from npcs inactive to the activation of another npcs. the dlybcs time guarantees non- overlapping chip selects and solves bus contentions in case of peripherals having long data float times. if dlybcs is less than or equal to six, six clk_spi periods will be inserted by default. otherwise, the following equation determines the delay: ? pcs: peripheral chip select this field is only used if fixed peripheral select is active (ps = 0). if pcsdec = 0: pcs = xxx0npcs[3:0] = 1110 pcs = xx01npcs[3:0] = 1101 pcs = x011npcs[3:0] = 1011 pcs = 0111npcs[3:0] = 0111 pcs = 1111forbidden (no peripheral is selected) (x = don?t care) if pcsdec = 1: npcs[3:0] output signals = pcs. ? llb: local loopback enable 1: local loopback path enabled. llb controls the local loopback on the data serializer for testing in master mode only (miso is internally connected on mosi). 0: local loopback path disabled. ? rxfifoen: fifo in reception enable 1: the fifo is used in reception (f our characters can be stored in the spi). 31 30 29 28 27 26 25 24 dlybcs 23 22 21 20 19 18 17 16 ---- pcs 15 14 13 12 11 10 9 8 -------- 76543210 llb rxfifoen wdrbt- modfdis - pcsdec ps mstr delay between chip selects dlybcs clkspi ---------------------- - =
419 32072d?04/2011 at32uc3a3/a4 0: the fifo is not used in reception (onl y one character can be stored in the spi). ? wdrbt: wait data read before transfer 1: in master mode, a transfer can start only if the rdr regist er is empty, i.e. does not contain any unread data. this mode prevents overrun error in reception. 0: no effect. in master mode, a transfer can be in itiated whatever the state of the rdr register is. ? modfdis: mode fault detection 1: mode fault detection is disabled. if the i/o controller does not have o pen-drain capability, mode fault detection must be disabled for proper operation of the spi. 0: mode fault detection is enabled. ? pcsdec: chip select decode 0: the chip selects are directly connected to a peripheral device. 1: the four chip select lines are co nnected to a 4- to 16-bit decoder. when pcsdec equals one, up to 15 chip select signals can be generated with the four lines using an external 4- to 16-bit decoder. the csrn registers define the characteristics of the 15 chip selects according to the following rules: csr0 defines peripheral chip select signals 0 to 3. csr1 defines peripheral chip select signals 4 to 7. csr2 defines peripheral chip select signals 8 to 11. csr3 defines peripheral chip select signals 12 to 14. ? ps: peripheral select 1: variable peripheral select. 0: fixed peripheral select. ? mstr: master/slave mode 1: spi is in master mode. 0: spi is in slave mode.
420 32072d?04/2011 at32uc3a3/a4 21.8.3 receive data register name: rdr access type: read-only offset: 0x08 reset value: 0x00000000 ? rd: receive data data received by the spi interface is stored in this register right-justified. unused bits read zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 rd[15:8] 76543210 rd[7:0]
421 32072d?04/2011 at32uc3a3/a4 21.8.4 transmit data register name: tdr access type: write-only offset: 0x0c reset value: 0x00000000 ? lastxfer: last transfer 1: the current npcs will be deasserted after the character wr itten in td has been transferred. when csrn.csaat is one, this allows to close the communication with the current serial peri pheral by raising the corresponding npcs line as soon as td transfer has completed. 0: writing a zero to this bit has no effect. this field is only used if variable peripheral select is active (mr.ps = 1). ? pcs: peripheral chip select if pcsdec = 0: pcs = xxx0npcs[3:0] = 1110 pcs = xx01npcs[3:0] = 1101 pcs = x011npcs[3:0] = 1011 pcs = 0111npcs[3:0] = 0111 pcs = 1111forbidden (no peripheral is selected) (x = don?t care) if pcsdec = 1: npcs[3:0] output signals = pcs this field is only used if variable peripheral select is active (mr.ps = 1). ? td: transmit data data to be transmitted by the spi interface is stored in this re gister. information to be transmitted must be written to the td r register in a right-justified format. 31 30 29 28 27 26 25 24 -------lastxfer 23 22 21 20 19 18 17 16 ---- pcs 15 14 13 12 11 10 9 8 td[15:8] 76543210 td[7:0]
422 32072d?04/2011 at32uc3a3/a4 21.8.5 status register name: sr access type: read-only offset: 0x10 reset value: 0x00000000 ? spiens: spi enable status 1: this bit is set when the spi is enabled. 0: this bit is cleared when the spi is disabled. ? undes: underrun error st atus (slave mode only) 1: this bit is set when a transfer begins whereas no data has been loaded in the tdr register. 0: this bit is cleared when the sr register is read. ? txempty: transmission registers empty 1: this bit is set when tdr and internal shifter are empty. if a transfer delay has been defined, txempty is set after the completion of such delay. 0: this bit is cleared as soon as data is written in tdr. ? nssr: nss rising 1: a rising edge occurred on nss pin since last read. 0: this bit is cleared when the sr register is read. ? ovres: overrun error status 1: this bit is set when an overrun has occurred. an overrun occu rs when rdr is loaded at least twice from the serializer since the last read of the rdr. 0: this bit is cleared when the sr register is read. ? modf: mode fault error 1: this bit is set when a mode fault occurred. 0: this bit is cleared when the sr register is read. ? tdre: transmit data register empty 1: this bit is set when the last data written in the tdr register has been transferred to the serializer. 0: this bit is cleared when data has been written to tdr and not yet transferred to the serializer. tdre equals zero when the spi is disabled or at re set. the spi enable command sets this bit to one. ? rdrf: receive data register full 1: data has been received and the received data has been transferr ed from the serializer to rdr since the last read of rdr. 0: no data has been received since the last read of rdr 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------spiens 15 14 13 12 11 10 9 8 - - - - - undes txempty nssr 76543210 - - - - ovres modf tdre rdrf
423 32072d?04/2011 at32uc3a3/a4 21.8.6 interrupt enable register name: ier access type: write-only offset: 0x14 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will set the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - - undes txempty nssr 76543210 - - - - ovres modf tdre rdrf
424 32072d?04/2011 at32uc3a3/a4 21.8.7 interrupt disable register name: idr access type: write-only offset: 0x18 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - - undes txempty nssr 76543210 - - - - ovres modf tdre rdrf
425 32072d?04/2011 at32uc3a3/a4 21.8.8 interrupt mask register name: imr access type: read-only offset: 0x1c reset value: 0x00000000 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. a bit in this register is cleared when the corresponding bit in idr is written to one. a bit in this register is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - - undes txempty nssr 76543210 - - - - ovres modf tdre rdrf
426 32072d?04/2011 at32uc3a3/a4 21.8.9 chip select register 0 name: csr0 access type: read/write offset: 0x30 reset value: 0x00000000 ? dlybct: delay between consecutive transfers this field defines the delay between two consecutive transfers wi th the same peripheral without removing the chip select. the delay is always inserted after each transfer and before removing the chip select if needed. when dlybct equals zero, no delay between consecutive transfers is inserted and the clock keeps its duty cycle over the character transfers. otherwise, the following equation determines the delay: ? dlybs: delay before spck this field defines the delay from npcs valid to the first valid spck transition. when dlybs equals zero, the npcs valid to spck transition is 1/2 the spck clock period. otherwise, the following equat ions determine the delay: ? scbr: serial clock baud rate in master mode, the spi interface uses a modulus counter to de rive the spck baud rate from the clk_spi. the baud rate is selected by writing a value from 1 to 255 in the scbr field. the following equations determine the spck baud rate: writing the scbr field to zero is forbidden. triggering a transfer while scbr is zero can lead to unpredictable results. at reset, scbr is zero and the user has to write it to a valid value before performing the first transfer. if a clock divider (scbrn) field is set to one and the other scbr fields differ from one, access on csn is correct but no corre ct access will be possible on other cs. 31 30 29 28 27 26 25 24 dlybct 23 22 21 20 19 18 17 16 dlybs 15 14 13 12 11 10 9 8 scbr 76543210 bits csaat csnaat ncpha cpol delay between consecutive transfers 32 dlybct clkspi ------------------------------------ = delay before spck dlybs clkspi --------------------- = spck baudrate clkspi scbr --------------------- =
427 32072d?04/2011 at32uc3a3/a4 ? bits: bits per transfer the bits field determines the number of data bits transferred. reserved values should not be used. ? csaat: chip select active after transfer 1: the peripheral chip select does not ri se after the last transfer is achieved. it remains active until a new transfer is requ ested on a different chip select. 0: the peripheral chip select line rises as soon as the last transfer is achieved. ? csnaat: chip select not active afte r transfer (ignored if csaat = 1) 0: the peripheral chip select does not rise between two transfers if the tdr is reloaded before the end of the first transfer a nd if the two transfers occur on the same chip select. 1: the peripheral chip select rises system atically between each transfe r performed on the same slave for a minimal duration of: (if dlybct field is different from 0) (if dlybct field equals 0) ? ncpha: clock phase 1: data is captured after the leading (inactive-to-active) e dge of spck and changed on the trailing (active-to-inactive) edge o f spck. 0: data is changed on the leading (inactive-to-active) edge of spck and captured after the trailing (active-to-inactive) edge o f spck. ncpha determines which edge of spck causes data to change and which edge causes data to be captured. ncpha is used with cpol to produce the requir ed clock/data relationship between master and slave devices. ?cpol: clock polarity 1: the inactive state value of spck is logic level one. 0: the inactive state value of spck is logic level zero. bits bits per transfer 0000 8 0001 9 0010 10 0011 11 0100 12 0101 13 0110 14 0111 15 1000 16 1001 4 1010 5 1011 6 1100 7 1101 reserved 1110 reserved 1111 reserved dlybcs clkspi ---------------------- - dlybcs 1 + clkspi -------------------------------- -
428 32072d?04/2011 at32uc3a3/a4 cpol is used to determine the inactive state value of the seri al clock (spck). it is used wit h ncpha to produce the required clock/data relationship between master and slave devices.
429 32072d?04/2011 at32uc3a3/a4 21.8.10 chip select register 1 name: csr1 access type: read/write offset: 0x34 reset value: 0x00000000 ? dlybct: delay between consecutive transfers this field defines the delay between two consecutive transfers wi th the same peripheral without removing the chip select. the delay is always inserted after each transfer and before removing the chip select if needed. when dlybct equals zero, no delay between consecutive transfers is inserted and the clock keeps its duty cycle over the character transfers. otherwise, the following equation determines the delay: ? dlybs: delay before spck this field defines the delay from npcs valid to the first valid spck transition. when dlybs equals zero, the npcs valid to spck transition is 1/2 the spck clock period. otherwise, the following equat ions determine the delay: ? scbr: serial clock baud rate in master mode, the spi interface uses a modulus counter to de rive the spck baud rate from the clk_spi. the baud rate is selected by writing a value from 1 to 255 in the scbr field. the following equations determine the spck baud rate: writing the scbr field to zero is forbidden. triggering a transfer while scbr is zero can lead to unpredictable results. at reset, scbr is zero and the user has to write it to a valid value before performing the first transfer. if a clock divider (scbrn) field is set to one and the other scbr fields differ from one, access on csn is correct but no corre ct access will be possible on other cs. 31 30 29 28 27 26 25 24 dlybct 23 22 21 20 19 18 17 16 dlybs 15 14 13 12 11 10 9 8 scbr 76543210 bits csaat csnaat ncpha cpol delay between consecutive transfers 32 dlybct clkspi ------------------------------------ = delay before spck dlybs clkspi --------------------- = spck baudrate clkspi scbr --------------------- =
430 32072d?04/2011 at32uc3a3/a4 ? bits: bits per transfer the bits field determines the number of data bits transferred. reserved values should not be used. ? csaat: chip select active after transfer 1: the peripheral chip select does not ri se after the last transfer is achieved. it remains active until a new transfer is requ ested on a different chip select. 0: the peripheral chip select line rises as soon as the last transfer is achieved. ? csnaat: chip select not active afte r transfer (ignored if csaat = 1) 0: the peripheral chip select does not rise between two transfers if the tdr is reloaded before the end of the first transfer a nd if the two transfers occur on the same chip select. 1: the peripheral chip select rises system atically between each transfe r performed on the same slave for a minimal duration of: (if dlybct field is different from 0) (if dlybct field equals 0) ? ncpha: clock phase 1: data is captured after the leading (inactive-to-active) e dge of spck and changed on the trailing (active-to-inactive) edge o f spck. 0: data is changed on the leading (inactive-to-active) edge of spck and captured after the trailing (active-to-inactive) edge o f spck. ncpha determines which edge of spck causes data to change and which edge causes data to be captured. ncpha is used with cpol to produce the requir ed clock/data relationship between master and slave devices. ?cpol: clock polarity 1: the inactive state value of spck is logic level one. 0: the inactive state value of spck is logic level zero. bits bits per transfer 0000 8 0001 9 0010 10 0011 11 0100 12 0101 13 0110 14 0111 15 1000 16 1001 4 1010 5 1011 6 1100 7 1101 reserved 1110 reserved 1111 reserved dlybcs clkspi ---------------------- - dlybcs 1 + clkspi -------------------------------- -
431 32072d?04/2011 at32uc3a3/a4 cpol is used to determine the inactive state value of the seri al clock (spck). it is used wit h ncpha to produce the required clock/data relationship between master and slave devices.
432 32072d?04/2011 at32uc3a3/a4 21.8.11 chip select register 2 name: csr2 access type: read/write offset: 0x38 reset value: 0x00000000 ? dlybct: delay between consecutive transfers this field defines the delay between two consecutive transfers wi th the same peripheral without removing the chip select. the delay is always inserted after each transfer and before removing the chip select if needed. when dlybct equals zero, no delay between consecutive transfers is inserted and the clock keeps its duty cycle over the character transfers. otherwise, the following equation determines the delay: ? dlybs: delay before spck this field defines the delay from npcs valid to the first valid spck transition. when dlybs equals zero, the npcs valid to spck transition is 1/2 the spck clock period. otherwise, the following equat ions determine the delay: ? scbr: serial clock baud rate in master mode, the spi interface uses a modulus counter to de rive the spck baud rate from the clk_spi. the baud rate is selected by writing a value from 1 to 255 in the scbr field. the following equations determine the spck baud rate: writing the scbr field to zero is forbidden. triggering a transfer while scbr is zero can lead to unpredictable results. at reset, scbr is zero and the user has to write it to a valid value before performing the first transfer. if a clock divider (scbrn) field is set to one and the other scbr fields differ from one, access on csn is correct but no corre ct access will be possible on other cs. 31 30 29 28 27 26 25 24 dlybct 23 22 21 20 19 18 17 16 dlybs 15 14 13 12 11 10 9 8 scbr 76543210 bits csaat csnaat ncpha cpol delay between consecutive transfers 32 dlybct clkspi ------------------------------------ = delay before spck dlybs clkspi --------------------- = spck baudrate clkspi scbr --------------------- =
433 32072d?04/2011 at32uc3a3/a4 ? bits: bits per transfer the bits field determines the number of data bits transferred. reserved values should not be used. ? csaat: chip select active after transfer 1: the peripheral chip select does not ri se after the last transfer is achieved. it remains active until a new transfer is requ ested on a different chip select. 0: the peripheral chip select line rises as soon as the last transfer is achieved. ? csnaat: chip select not active afte r transfer (ignored if csaat = 1) 0: the peripheral chip select does not rise between two transfers if the tdr is reloaded before the end of the first transfer a nd if the two transfers occur on the same chip select. 1: the peripheral chip select rises system atically between each transfe r performed on the same slave for a minimal duration of: (if dlybct field is different from 0) (if dlybct field equals 0) ? ncpha: clock phase 1: data is captured after the leading (inactive-to-active) e dge of spck and changed on the trailing (active-to-inactive) edge o f spck. 0: data is changed on the leading (inactive-to-active) edge of spck and captured after the trailing (active-to-inactive) edge o f spck. ncpha determines which edge of spck causes data to change and which edge causes data to be captured. ncpha is used with cpol to produce the requir ed clock/data relationship between master and slave devices. ?cpol: clock polarity 1: the inactive state value of spck is logic level one. 0: the inactive state value of spck is logic level zero. bits bits per transfer 0000 8 0001 9 0010 10 0011 11 0100 12 0101 13 0110 14 0111 15 1000 16 1001 4 1010 5 1011 6 1100 7 1101 reserved 1110 reserved 1111 reserved dlybcs clkspi ---------------------- - dlybcs 1 + clkspi -------------------------------- -
434 32072d?04/2011 at32uc3a3/a4 cpol is used to determine the inactive state value of the seri al clock (spck). it is used wit h ncpha to produce the required clock/data relationship between master and slave devices.
435 32072d?04/2011 at32uc3a3/a4 21.8.12 chip select register 3 name: csr3 access type: read/write offset: 0x3c reset value: 0x00000000 ? dlybct: delay between consecutive transfers this field defines the delay between two consecutive transfers wi th the same peripheral without removing the chip select. the delay is always inserted after each transfer and before removing the chip select if needed. when dlybct equals zero, no delay between consecutive transfers is inserted and the clock keeps its duty cycle over the character transfers. otherwise, the following equation determines the delay: ? dlybs: delay before spck this field defines the delay from npcs valid to the first valid spck transition. when dlybs equals zero, the npcs valid to spck transition is 1/2 the spck clock period. otherwise, the following equat ions determine the delay: ? scbr: serial clock baud rate in master mode, the spi interface uses a modulus counter to de rive the spck baud rate from the clk_spi. the baud rate is selected by writing a value from 1 to 255 in the scbr field. the following equations determine the spck baud rate: writing the scbr field to zero is forbidden. triggering a transfer while scbr is zero can lead to unpredictable results. at reset, scbr is zero and the user has to write it to a valid value before performing the first transfer. if a clock divider (scbrn) field is set to one and the other scbr fields differ from one, access on csn is correct but no corre ct access will be possible on other cs. 31 30 29 28 27 26 25 24 dlybct 23 22 21 20 19 18 17 16 dlybs 15 14 13 12 11 10 9 8 scbr 76543210 bits csaat csnaat ncpha cpol delay between consecutive transfers 32 dlybct clkspi ------------------------------------ = delay before spck dlybs clkspi --------------------- = spck baudrate clkspi scbr --------------------- =
436 32072d?04/2011 at32uc3a3/a4 ? bits: bits per transfer the bits field determines the number of data bits transferred. reserved values should not be used. ? csaat: chip select active after transfer 1: the peripheral chip select does not ri se after the last transfer is achieved. it remains active until a new transfer is requ ested on a different chip select. 0: the peripheral chip select line rises as soon as the last transfer is achieved. ? csnaat: chip select not active afte r transfer (ignored if csaat = 1) 0: the peripheral chip select does not rise between two transfers if the tdr is reloaded before the end of the first transfer a nd if the two transfers occur on the same chip select. 1: the peripheral chip select rises system atically between each transfe r performed on the same slave for a minimal duration of: (if dlybct field is different from 0) (if dlybct field equals 0) ? ncpha: clock phase 1: data is captured after the leading (inactive-to-active) e dge of spck and changed on the trailing (active-to-inactive) edge o f spck. 0: data is changed on the leading (inactive-to-active) edge of spck and captured after the trailing (active-to-inactive) edge o f spck. ncpha determines which edge of spck causes data to change and which edge causes data to be captured. ncpha is used with cpol to produce the requir ed clock/data relationship between master and slave devices. ?cpol: clock polarity 1: the inactive state value of spck is logic level one. 0: the inactive state value of spck is logic level zero. bits bits per transfer 0000 8 0001 9 0010 10 0011 11 0100 12 0101 13 0110 14 0111 15 1000 16 1001 4 1010 5 1011 6 1100 7 1101 reserved 1110 reserved 1111 reserved dlybcs clkspi ---------------------- - dlybcs 1 + clkspi -------------------------------- -
437 32072d?04/2011 at32uc3a3/a4 cpol is used to determine the inactive state value of the seri al clock (spck). it is used wit h ncpha to produce the required clock/data relationship between master and slave devices.
438 32072d?04/2011 at32uc3a3/a4 21.8.13 write protection control register register name: wpcr access type: read-write offset: 0xe4 reset value: 0x00000000 ? spiwpkey: spi write protection key password if a value is written in spiwpen, the value is taken into acc ount only if spiwpkey is written wit h ?spi? (spi written in ascii code, i.e. 0x535049 in hexadecimal). ? spiwpen: spi write protection enable 1: the write protection is enabled 0: the write protection is disabled 31 30 29 28 27 26 25 24 spiwpkey[23:16] 23 22 21 20 19 18 17 16 spiwpkey[15:8] 15 14 13 12 11 10 9 8 spiwpkey[7:0] 76543210 -------spiwpen
439 32072d?04/2011 at32uc3a3/a4 21.8.14 write protection status register register name: wpsr access type: read-only offset: 0xe8 reset value: 0x00000000 ? spiwpvsrc: spi write protection violation source this field indicates the peripheral bus offset of th e register concerned by the violation (mr or csrx) 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 spiwpvsrc 76543210 - - - - - spiwpvs
440 32072d?04/2011 at32uc3a3/a4 ? spiwpvs: spi write prot ection violation status ? ? ? ? ? ? ? ? ? ? ? ? spiwpvs value violation type 1 the write protection has blocked a write access to a protected register (since the last read). 2 software reset has been performed while write protection was enabled (since the last read or since the last write acce ss on mr, ier, idr or csrx). 3 both write protection violation and software reset with write protection enabled have occurred since the last read. 4 write accesses have been detected on mr (while a chip select was active) or on csri (while the chip select ?i? was active) since the last read. 5 the write protection has blocked a write acce ss to a protected register and write accesses have been detected on mr (while a chip select was active) or on csri (while the chip select ?i? was active) since the last read. 6 software reset has been performed while write protection was enabled (since the last read or since the last write access on mr, ier, idr or csrx) and some write accesses have been detected on mr (while a chip select was active) or on csri (while the chip select ?i? was active) since the last read. 7 - the write protection has blocked a write access to a protected register. and - software reset has been performed while write protection was enabled. and - write accesses have been detected on mr (while a chip select was active) or on csri (while the chip select ?i? was active) since the last read.
441 32072d?04/2011 at32uc3a3/a4 21.8.15 version register register name: version access type: read-only offset: 0xfc reset value: ? ? mfn reserved. no functionality associated. ? version version number of the module. no functionality associated. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ---- mfn 15 14 13 12 11 10 9 8 version[11:8] 76543210 version[7:0]
442 32072d?04/2011 at32uc3a3/a4 21.9 module configuration the specific configuration for each spi instance is listed in the following tables.the module bus clocks listed here are connecte d to the system bus clocks. pleas e refer to the power manager section for details. table 21-4. module clock name module name clock name spi0 clk_spi0 spi1 clk_spi1 table 21-5. register reset values register reset value version 0x00000210
443 32072d?04/2011 at32uc3a3/a4 22. two-wire slave interface (twis) rev: 1.0.0.1 22.1 features ? compatible with i 2 c standard ? in transfer speeds ? 7 and 10-bit and general call addressing ? compatible with smbus standard ? hardware packet error checking (crc) ge neration and verification with ack response ? smbalert interface ? 25 ms clock low timeout delay ? 25 ms slave cumulative clock low extend time ? compatible with pmbus ? dma interface for reducing cpu load ? arbitrary transfer lengths, including 0 data bytes ? optional clock stretching if transmit or receive buffers not ready for data transfer ? 32-bit peripheral bus interface fo r configuration of the interface 22.2 overview the atmel two-wire interface slave (twis) interconnects components on a unique two-wire bus, made up of one clock line and one data line with speeds of up to 400 kbit/s, based on a byte-oriented transfer format. it can be used with any atmel two-wire interface bus i2c or smbus compatible master. twis is always a bus slave and can transfer sequential or single bytes. below, table 22-1 on page 443 lists the compatibility level of the atmel two-wire slave interface and a full i2c compatible device. note: 1. start + b000000001 + ack + sr table 22-1. atmel twis compatibility with i2c standard i2c standard atmel twis standard-mode (100 kbit/s) supported fast-mode (400 kbit/s) supported 7 or 10 bits slave addressing supported start byte (1) not supported repeated start (sr) condition supported ack and nak management supported slope control and input filtering (fast mode) supported clock stretching supported
444 32072d?04/2011 at32uc3a3/a4 below, table 22-2 on page 444 lists the compatibility level of the atmel two-wire slave interface and a full smbus compatible device. 22.3 list of abbreviations 22.4 block diagram figure 22-1. block diagram table 22-2. atmel twis compatibilit y with smbus standard smbus standard atmel twis bus timeouts supported address resolution protocol supported alert supported packet error checking supported table 22-3. abbreviations abbreviation description twi two-wire interface a acknowledge na non acknowledge pstop sstart sr repeated start sadr slave address adr any address except sadr r read wwrite peripheral bus bridge two-wire interface i/o controller twck twd interrupt controller twi interrupt power manager clk_twis twalm
445 32072d?04/2011 at32uc3a3/a4 22.5 application block diagram 22.6 i/o lines description 22.7 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 22.7.1 i/o lines twd and twck are bidirectional lines, connected to a positive supply voltage via a current source or pull-up resistor (see figure 22-4 on page 447 ). when the bus is free, both lines are high. the output stages of devices connected to the bus must have an open-drain or open-col- lector to perform the wired-and function. twalm is used to implement the optional smbus smbalert signal. twalm, twd, and twck pins may be multiple xed with i/o controller lines. to enable the twis, the programmer must perform the following steps: ? program the i/o controller to: ? dedicate twd, twck and optionally twalm as peripheral lines. ? define twd, twck and optionally twalm as open-drain. 22.7.2 power management if the cpu enters a sleep mode that disables cl ocks used by the twis, the twis will stop func- tioning and resume operation after the system wakes up from sleep mode. 22.7.3 clocks the clock for the twis bus interface (clk_twis) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to dis- able the twis before disabling the clock, to avoid freezing the twis in an undefined state. 22.7.4 dma the twis dma handshake interface is connected to the peripheral dma controller. using the twis dma functionality requires the peripheral dma controller to be programmed after setting up the twis. 22.7.5 interrupts the twis interrupt request lines are connected to the interrupt controller. using the twis inter- rupts requires the interrupt controller to be programmed first. table 22-4. i/o lines description pin name pin description type twd two-wire serial data input/output twck two-wire serial clock input/output twalm smbus smbalert input/output
446 32072d?04/2011 at32uc3a3/a4 22.7.6 debug operation when an external debugger forces the cpu into debug mode, the twis continues normal oper- ation. if the twis is configured in a way that requires it to be periodically serviced by the cpu through interrupts or similar, improper operation or data loss may result during debugging. 22.8 functional description 22.8.1 transfer format the data put on the twd line must be 8 bits long. data is transferred msb first; each byte must be followed by an acknowledgement. the number of bytes per transfer is unlimited (see figure 22-3 on page 446 ). each transfer begins with a start condition and terminates with a stop condition (see figure 22-2 on page 446 ). ? a high-to-low transition on the twd line while twck is high defines the start condition. ? a low-to-high transition on the twd line while twck is high defines a stop condition. figure 22-2. start and stop conditions figure 22-3. transfer format 22.8.2 operation twis has two modes of operation: ? slave transmitter mode ? slave receiver mode a master is a device which starts and stops a transfer and generates the twck clock. a slave is assigned an address and responds to requests from the master. these modes are described in the following chapters. twd twck start stop twd twck start address r/w ack data ack data ack stop
447 32072d?04/2011 at32uc3a3/a4 figure 22-4. typical application block diagram 22.8.2.1 bus timing the timing register (tr) is used to control the timing of bus signals driven by twis. tr describes bus timings as a function of cycles of the prescaled clk_twis. the clock prescaling can be selected through tr.exp. tr has the following fields: tlows: prescaled clock cycles used to time smbus timeout t low:sext . ttout: prescaled clock cycles us ed to time smbus timeout t timeout . sudat: non-prescaled clock cycles for data setup and hold count. used to time t su_dat . exp: specifies the clock prescaler setting used for the smbus timeouts. host with twi interface twd twck atmel twi serial eeprom i2c rtc i2c lcd controller slave 1 slave 2 slave 3 vdd i2c temp. sensor slave 4 rp: pull up value as given by the i2c standard rp rp f prescaled f clk twis ? 2 exp 1 + ) () --------------------------- =
448 32072d?04/2011 at32uc3a3/a4 figure 22-5. bus timing diagram 22.8.2.2 setting up and performing a transfer operation of twis is mainly controlled by the control register (cr). th e following list presents the main steps in a typical communication: 1. before any transfers can be performed, bus timings must be configured by program- ming the timing register (tr). 2. if a dma controller is to be used for the transfers, it must be set up. 3. the control register (cr) must be configured with information such as the slave address, smbus mode, packet error checking (pec), number of bytes to transfer, and which addresses to match. the interrupt system can be set up to give interr upt request on specific events or error condi- tions, for example when a byte has been received. the nbytes register is only used in smbus mode, when pec is enabled. in i2c mode or in smbus mode when pec is disabled, the nbytes register is not used, and should be written to 0. nbytes is updated by hardware, so in order to avoid hazards, software updates of nbytes can only be done through writes to the nbytes register. 22.8.2.3 address matching twis can be set up to match several different addresses. more than one address match may be enabled simultaneously, allowing twis to be assigned to several addresses. the address matching phase is initiated after a start or repeated start condition. when twis receives an address that generates an address matc h, an ack is automatically returned to the master. in i2c mode: ? the address in cr.adr is checked fo r address match if cr.smatch is set. ? the general call address is checked fo r address match if cr.gcmatch is set. in smbus mode: s t hd:sta t low t su:dat t high t hd:dat t low p t su:sto sr t su:sta t su:dat
449 32072d?04/2011 at32uc3a3/a4 ? the address in cr.adr is checked fo r address match if cr.smatch is set. ? the alert response address is checked for address match if cr.smal is set. ? the default address is checked for address match if cr.smda is set. ? the host header address is checked for address match if cr.smhh is set. 22.8.2.4 clock stretching any slave or bus master taking part in a transfer may extend the twck low period at any time. twis may extend the twck low period after each byte transfer if cr.stren=1 and: ? module is in slave transmitter mode, data should be transmitted, but thr is empty, or ? module is in slave receiver mode, a byte has been received and placed into the internal shifter, but rhr is full, or ? stretch-on-address-match bit cr.soam=1 and slave was addressed. bus clock remains stretched until all address match bits in sr have been cleared. if cr.stren=0 and: ? module is in slave transmitter mode, data shou ld be transmitted but thr is empty: transmit the value present in thr (the last transmitted byte or reset value), and set sr.urun. ? module is in slave receiver mode, a byte has been received and placed into the internal shifter, but rhr is full: discard the received byte and set sr.orun. 22.8.2.5 bus errors if a bus error (misplaced start or stop) cond ition is detected, the sr.buserr bit is set and twis waits for a new start condition. 22.8.3 slave transmitter mode if twis matches an address in which the r/w bit in the twi address phase transfer is set, it will enter slave transmitter mode and set the sr.tra bit (note that sr.tra is set one clk_twis cycle after the relevant address match bit in the same register is set). after the address phase, the following actions are performed: 1. if smbus mode and pec is used, nbytes must be set up with the number of bytes to transmit. this is necessary in order to know when to transmit pec byte. nbytes can also be used to count the number of bytes received if using dma. 2. byte to transmit depends on i2c/smbus mode and cr.pec: ? if in i2c mode or cr.pec=0 or nbytes!=0 : twis waits until thr contains a valid data byte, possibly stretching the low period of twck. after thr contains a valid data byte, the data byte is transferred to a shifter, and then sr.txrdy is changed to one because the thr is empty again. ? smbus mode and cr.pec=1: if nbytes=0, the generated pec byte is automatically transmitted in stead of a data byte from thr. twck will not be stretched by twis. 3. the data byte in the shifter is transmitted. 4. nbytes is updated. if cr.cup is set, nbytes is incremented, otherwise nbytes is decremented. 5. after each data byte has been transmitted, the master transmits an ack (acknowledge) or nak (not acknowledge) bit. if a nak bit is received by twis, the sr.nak bit is set. note that this is done two clk_twis cycles after twck has been sampled by twis to be high (see figure 22-8 on page 451 ). the nak indicates that the transfer is finished,
450 32072d?04/2011 at32uc3a3/a4 and twis will wait for a stop or repeated start. if an ack bit is received, the sr.nak bit remains low. the ack indicates that more data should be transmitted, so jump to step 2. at the end of the ack/nak clock cycle, the sr.btf (byte transfer fin- ished) bit is set. note that this is done two clk_twis cycles after twck has been sampled by twis to be low (see figure 22-8 on page 451 ). also note that in the event that sr.nak bit is set, it must not be cleared before the sr.btf bit is set to ensure cor- rect twis behavior. 6. if stop is received, sr.tcomp and sr.sto will be set. 7. if repeated start is received, sr.rep will be set. the twi transfers require the receiver to acknowledge each received data byte. during the acknowledge clock pulse (9th pulse), the slave releases the data line (high), enabling the mas- ter to pull it down in order to generate the acknowledge. the slave polls the data line during this clock pulse and sets the nak bit in the status register if the master does not acknowledge the data byte. a nak means that the master does not wish to receive additional data bytes. as with the other status bits, an interrupt can be gener ated if enabled in the interrupt enable register (ier). txrdy is used as transmit ready for the pe ripheral dma controller transmit channel. the end of the complete transfer is marked by the sr.tcomp bit set to one. see figure 22-6 on page 450 and figure 22-7 on page 450 . figure 22-6. slave transmitter with one data byte figure 22-7. slave transmitter with multiple data bytes tcomp txrdy write thr (data) stop sent by master twd adatan sdadrr p nbytes set to 1 adata na sdadrr data n+5a p data n+m n tco m p txrdy write thr (data n) nbytes set to m stop sent by master twd write thr (data n+1) write thr (data n+m) last data sent
451 32072d?04/2011 at32uc3a3/a4 figure 22-8. timing relationship between twck, sr.nak, and sr.btf 22.8.4 slave receiver mode if twis matches an address in which the r/w bit in the twi address phase transfer is cleared, it will enter slave receiver mode and clear sr.t ra (note that sr.tra is cleared one clk_twis cycle after the relevant address match bit in the same register is set). after the address phase, the following is repeated: 1. if smbus mode and pec is used, nbytes must be set up with the number of bytes to receive. this is necessary in order to know which of the received bytes is the pec byte. nbytes can also be used to count the number of bytes received if using dma. 2. receive a byte. set sr.btf when done. 3. update nbytes. if cr.cup is written to one, nbytes is incremented, otherwise nbytes is decremented. nbytes is usually configured to count downwards if pec is used. 4. after a data byte has been received, the slave transmits an ack or nak bit. for ordi- nary data bytes, the cr.ack field controls if an ack or nak should be returned. if pec is enabled and the last byte received was a pec byte (indicated by nbytes=0), twis will automatically return an ack if the pec value was correct, otherwise a nak will be returned. 5. if stop is received, sr.tcomp will be set. 6. if repeated start is received, sr.rep will be set. the twi transfers require the receiver to acknowledge each received data byte. during the acknowledge clock pulse (9th pulse), the master releases the data line (high), enabling the slave to pull it down in order to generate the acknowledge. the master polls the data line during this clock pulse. rxrdy is used as receive ready for the peripheral dma controller receive channel. data (lsb) n p twck sr.nak sr.btf t 1 t 1 t 1 : (clk_twis period) x 2 twd
452 32072d?04/2011 at32uc3a3/a4 figure 22-9. slave receiver with one data byte figure 22-10. slave receiver with multiple data bytes 22.8.5 using the peripheral dma controller the use of the peripheral dma controller signi ficantly reduces the cpu load. the programmer can set up ring buffers for the dma controller, containing data to transmit or free buffer space to place received data. by initializing nbyt es to 0 before a transfer, and setting cr.cup, nbytes is incremented by 1 each time a data has been transmitted or received. this allows the programmer to detect how much data was actually transferred by the dma system. to assure correct behavior, respect the following programming sequences: 22.8.5.1 data transmit with the peripheral dma controller 1. initialize the transmit peripheral dma controller (memory pointers, size, etc.). 2. configure the twis (adr, nbytes, etc.). 3. start the transfer by setting the peripheral dma controller txten bit. 4. wait for the peripheral dma controller end tx flag. 5. disable the peripheral dma controller by setting the peripheral dma controller txdis bit. 22.8.5.2 data receive with th e peripheral dma controller 1. initialize the receive peripheral dma controller (memory pointers, size - 1 , etc.). 2. configure the twis (adr, nbytes, etc.). 3. start the transfer by setting the peripheral dma controller rxten bit. 4. wait for the peripheral dma controller end rx flag. a sdadrw data ap tcomp rx r dy read rhr twd a a sdadrw data na a data (n+1) a data (n+m) dat a (n+m)-1 p twd tco m p rx r dy read rhr data n read rhr dat a (n+1) read rhr dat a (n+m)-1 read rhr data (n+m)
453 32072d?04/2011 at32uc3a3/a4 5. disable the peripheral dma controller by setting the peripheral dma controller rxdis bit. 22.8.6 smbus mode smbus mode is enabled when cr.smen is writte n to one. smbus mode operation is similar to i2c operation with the following exceptions: ? only 7-bit addressing can be used. ? the smbus standard describes a set of timeout values to ensure progress and throughput on the bus. these timeout values must be programmed into tr. ? transmissions can optionally include a crc byte, called packet error check (pec). ? a dedicated bus line, smbalert, allows a slave to get a master?s attention. ? a set of addresses have been reserved for protocol handling, such as alert response address (ara) and host header (hh) addres s. address matching on these addresses can be enabled by configuring cr appropriately. 22.8.6.1 packet error checking each smbus transfer can optionally end with a crc byte, called the pec byte. writing a one to cr.pecen enables automatic pec handling in the current transfer. the pec generator is always updated on every bit transmitted or received, so that pec handling on following linked transfers will be correct. in slave receiver mode, the master calculates a pec value and transmits it to the slave after all data bytes have been tr ansmitted. upon reception of this pec byte, the slave will compare it to the pec value it has computed itself. if the values match, the data was received correctly, and the slave will return an ack to th e master. if the pec values differ, data was corrupted, and the slave will return a nak value. the sr.smbpece rr bit is set automatically if a pec error occurred. in slave transmitter mode, the slave calculates a pec value and transmits it to the master after all data bytes have been transm itted. upon reception of this pec byte, the master will compare it to the pec value it has computed itself. if the values match, the data was received correctly. if the pec values differ, data was corrupted, and the master must take appropriate action. the pec byte is automatically inserted in a slave transmitter transmission if pec enabled when nbytes reaches zero. the pec byte is identified in a slave receiver transmission if pec enabled when nbytes reaches zero. nbytes must therefore be set to the total number of data bytes in the transmission, including the pec byte. 22.8.6.2 timeouts the timing register (tr) configures the smbus timeout values. if a timeout occurs, the slave will leave the bus. the sr.smbtout bit is also set. 22.8.6.3 smbalert a slave can get the master?s attention by pulling the smbalert line low. this is done by setting the cr.smbal bit. this will also enable address match on the alert response address (ara).
454 32072d?04/2011 at32uc3a3/a4 22.8.7 identifying bus events this chapter lists the different bus events, and ho w these affects bits in the twis registers. this is intended to help writing drivers for the twis. table 22-5. bus events event effect slave transmitter has sent a data byte sr.thr is cleared. sr.btf is set. the value of the ack bit sent immediately after the data byte is given by cr.ack. slave receiver has received a data byte sr.rhr is set. sr.btf is set. sr.nak updated according to value of ack bit received from master. start+sadr on bus, but address is to another slave none. start+sadr on bus, current slave is addressed, but address match enable bit in cr is not set none. start+sadr on bus, current slave is addressed, corresponding address match enable bit in cr set correct address match bit in sr is set. sr.tra updated according to transfer direction (updating is done one clk_twis cycle af ter address match bit is set) slave enters appropriate transfer direction mode and data transfer can commence. start+sadr on bus, current slave is addressed, corresponding address match enable bit in cr set, sr.stren and sr.soam are set. correct address match bit in sr is set. sr.tra updated according to transfer direction (updating is done one clk_twis cycle af ter address match bit is set). slave stretches twck immediately after transmitting the address ack bit. twck remains stretched until all address match bits in sr have been cleared. slave the enters appropriate transfer direction mode and data transfer can commence. repeated start received after being addressed sr.rep set. sr.tcomp unchanged. stop received after being addressed sr.sto set. sr.tcomp set. start, repeated start or stop received in illegal position on bus sr.buserr set. data is to be received in slave receiver mode, sr.stren is set, and rhr is full twck is stretched until rhr has been read. data is to be transmitted in slave receiver mode, sr.stren is set, and thr is empty twck is stretched until thr has been written.
455 32072d?04/2011 at32uc3a3/a4 data is to be received in slave receiver mode, sr.stren is cleared, and rhr is full twck is not stretched, read data is discarded. sr.orun is set. data is to be transmitted in slave receiver mode, sr.stren is cleared, and thr is empty twck is not stretched, previous c ontents of thr is written to bus. sr.urun is set. smbus timeout received sr.smbtout is set. twck and twd are immediately released. slave transmitter in smbus pec mode has transmitted a pec byte, that was not identical to the pec calculated by the master receiver. master receiver will transmit a nak as usual after the last byte of a master receiver transfer. master receiver will retry th e transfer at a later time. slave receiver discovers smbus pec error sr.smbpecerr is set. nak returned after the data byte. table 22-5. bus events event effect
456 32072d?04/2011 at32uc3a3/a4 22.9 user interface note: 1. the reset values for these registers are devi ce specific. please refer to the module configura- tion section at the end of this chapter. table 22-6. twis register memory map offset register register name access reset 0x00 control register cr read/write 0x00000000 0x04 nbytes register nbytes read/write 0x00000000 0x08 timing register tr read/write 0x00000000 0x0c receive holding register rhr read-only 0x00000000 0x10 transmit holding register thr write-only 0x00000000 0x14 packet error check register pecr read-only 0x00000000 0x18 status register sr read-only 0x00000002 0x1c interrupt enable register ier write-only 0x00000000 0x20 interrupt disable register idr write-only 0x00000000 0x24 interrupt mask register imr read-only 0x00000000 0x28 status clear register scr write-only 0x00000000 0x2c parameter register pr read-only (1) 0x30 version register vr read-only (1)
457 32072d?04/2011 at32uc3a3/a4 22.9.1 control register name: cr access type: read/write offset :0x00 reset value: 0x00000000 ? tenbit: ten bit address match write this bit to zero to disable ten bit address match. write this bit to one to enable ten bit address match. ? adr: slave address slave address used in slave address match. bits 9: 0 are used if in 10-bit mode, bits 6:0 otherwise. ? soam: stretch clock on address match writing this bit to zero will not strech bus clock after address match. writing this bit to one will strech bus clock after address match. ? cup: nbytes count up writing this bit to zero causes nbytes to count down (decrement) per byte transferred. writing this bit to one causes nbytes to count up (increment) per byte transferred. ? ack: slave receiver data phase ack value writing this bit to zero causes a low value to be returned in the ack cycle of the data phase in slave receiver mode. writing this bit to one causes a high value to be returned in the ack cycle of the data phase in slave receiver mode. ? pecen: packet error checking enable writing this bit to zero disables smbus pec (crc) generation and check. writing this bit to one enables smbus pec (crc) generation and check. ? smhh: smbus host header writing this bit to zero causes twis not to acknowledge the smbus host header. writing this bit to one causes twis to acknowledge the smbus host header. ? smda: smbus default address writing this bit to zero causes twis not to acknowledge the smbus default address. writing this bit to one causes twis to acknowledge the smbus default address. ? smbalert: smbus alert writing this bit to zero causes twis to release the smbalert line and not to acknowledge the smbus alert response address (ara). writing this bit to one causes twis to pull down the smbalert line and to acknowledge the smbus alert response address (ara). 31 30 29 28 27 26 25 24 ---- tenbit adr[9:8] 23 22 21 20 19 18 17 16 adr[7:0] 15 14 13 12 11 10 9 8 soam cup ack pecen smhh smda smbalert 76543210 swrst - - stren gcmatch smatch smen sen
458 32072d?04/2011 at32uc3a3/a4 ? swrst: software reset this bit will always read as 0. writing a zero to this bit has no effect. writing a one to this bit resets the twis. ? stren: clock stretch enable writing this bit to zero disables clock stretching if rhr/thr buffer full/empt y. may cause over/underrun. writing this bit to one enables clock stretching if rhr/thr buffer full/empty. ? gcmatch: general call address match writing this bit to zero causes twis no t to acknowledge the general call address. writing this bit to one causes twis to acknowledge the general call address. ? smatch: slave address match writing this bit to zero causes twis not to acknowledge the slave address. writing this bit to one causes twis to acknowledge the slave address. ? smen: smbus mode enable writing this bit to zero disables smbus mode. writing this bit to one enables smbus mode. ? sen: slave enable writing this bit to zero disables the slave interface. writing this bit to one enables the slave interface.
459 32072d?04/2011 at32uc3a3/a4 22.9.2 nbytes register name: nbytes access type: read/write offset :0x04 reset value: 0x00000000 ? nbytes: number of bytes to transfer writing to this field updates the nbytes counter. can also be r ead to to learn the progress of the transfer. can be incremented or decremented automatically by hardware. 31 30 29 28 27 26 25 24 - 23 22 21 20 19 18 17 16 - 15 14 13 12 11 10 9 8 - 76543210 nbytes
460 32072d?04/2011 at32uc3a3/a4 22.9.3 timing register name: tr access type: read/write offset :0x08 reset value: 0x00000000 ? exp: clock prescaler used to specify how to prescale the smbus tlows counter. the counter is prescaled according to the following formula: ? sudat: data setup cycles non-prescaled clock cycles for data setup count. used to time t su_dat . data is driven sudat cycles after twck low detected. this timing is used for timing the ack/nak bits, and any data bits driven in slave transmitter mode. ? ttout: smbus ttimeout cycles prescaled clock cycles used to time smbus t timeout . ? tlows: smbus tlow:sext cycles prescaled clock cycles used to time smbus t low:sext . 31 30 29 28 27 26 25 24 exp - 23 22 21 20 19 18 17 16 sudat 15 14 13 12 11 10 9 8 ttout 76543210 tlows f prescaled f clkpb 2 exp 1 + () ----------------------- - =
461 32072d?04/2011 at32uc3a3/a4 22.9.4 receive holding register name: rhr access type: read-only offset :0x0c reset value: 0x00000000 ? rxdata: received data byte when the rxrdy bit in the status regist er (sr) is set, this field contains a byte received from the twi bus. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 rxdata
462 32072d?04/2011 at32uc3a3/a4 22.9.5 transmit holding register name: thr access type: write-only offset :0x10 reset value: 0x00000000 ? txdata: data byte to transmit write data to be transf erred on the twi bus here. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 txdata
463 32072d?04/2011 at32uc3a3/a4 22.9.6 packet error check register name: pecr access type: read-only offset :0x14 reset value: 0x00000000 ? pec: calculated pec value the calculated pec value. updated automatical ly by hardware after each byte has been transferred. reset by hardware after a stop condition. provided if the user manu ally wishes to control when the pec byte is transmitted, or wishes to access the pec value for other reasons. in ordinary operation, the pec handling is done automatically by hardware. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 pec
464 32072d?04/2011 at32uc3a3/a4 22.9.7 status register name: sr access type: read-only offset :0x18 reset value: 0x000000002 ? btf: byte transfer finished this bit is set when byte transfer has completed. this bit is cleared when the corresponding bit in scr is written to one. ? rep: repeated start received this bit is set when repeated start condition received. this bit is cleared when the corresponding bit in scr is written to one. ? sto: stop received this bit is set when stop condition received. this bit is cleared when the corresponding bit in scr is written to one. ? smbdam: smbus default address match this bit is set when received address matched smbus default address. this bit is cleared when the corresponding bit in scr is written to one. ? smbhhm: smbus host header address match this bit is set when received address matched smbus host header address. this bit is cleared when the corresponding bit in scr is written to one. ? smbalertm: smbus alert response address match this bit is set when received address matched smbus alert response address. this bit is cleared when the corresponding bit in scr is written to one. ? gcm: general call match this bit is set when received address matched general call address. this bit is cleared when the corresponding bit in scr is written to one. ? sam: slave address match this bit is set when received address matched slave address. this bit is cleared when the corresponding bit in scr is written to one. ? buserr: bus error this bit is set when a misplaced start or stop condition has occurred. this bit is cleared when the corresponding bit in scr is written to one. 31 30 29 28 27 26 25 24 - 23 22 21 20 19 18 17 16 btf rep sto smbdam smbhhm smbalertm gcm sam 15 14 13 12 11 10 9 8 - buserr smbpecerr smbtout - - - nak 76 5 43210 orun urun tra - tcomp sen txrdy rxrdy
465 32072d?04/2011 at32uc3a3/a4 ? smbpecerr: smbus pec error this bit is set when smbus pec error has occurred. this bit is cleared when the corresponding bit in scr is written to one. ? smbtout: smbus timeout this bit is set when smbus timeout has occurred. this bit is cleared when the corresponding bit in scr is written to one. ? nak: nak received this bit is set when nak was received from master during slave transmitter operation. this bit is cleared when the corresponding bit in scr is written to one. ? orun: overrun this bit is set when overrun has occurred in slave receiver mode. can only occur if cr.stren=0. this bit is cleared when the corresponding bit in scr is written to one. ? urun: underrun this bit is set when underrun has occurred in slave transmitter mode. can only occur if cr.stren=0. this bit is cleared when the corresponding bit in scr is written to one. ? tra: transmitter mode 0: the slave is in slave receiver mode. 1: the slave is in slave transmitter mode. ? tcomp: transmis sion complete this bit is set when transmission is complete. set after receiving a stop after being addressed. this bit is cleared when the corresponding bit in scr is written to one. ? sen: slave enabled 0: the slave interface is disabled. 1: the slave interface is enabled. ? txrdy: tx buffer ready 0: the tx buffer is full and should not be written to. 1: the tx buffer is empty, and can accept new data. ? rxrdy: rx buffer ready 0: no rx data ready in rhr. 1: rx data is ready to be read from rhr.
466 32072d?04/2011 at32uc3a3/a4 22.9.8 interrupt enable register name: ier access type: write-only offset :0x1c reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will set the corresponding bit in imr. 31 30 29 28 27 26 25 24 -- - ----- 23 22 21 20 19 18 17 16 btf rep sto smbdam smbhhm smbalertm gcm sam 15 14 13 12 11 10 9 8 - buserr smbpecerr smbtout - - - nak 76 5 43210 orun urun - - tcomp - txrdy rxrdy
467 32072d?04/2011 at32uc3a3/a4 22.9.9 interrupt disable register name: idr access type: write-only offset :0x20 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in imr. 31 30 29 28 27 26 25 24 -- - ----- 23 22 21 20 19 18 17 16 btf rep sto smbdam smbhhm smbalertm gcm sam 15 14 13 12 11 10 9 8 - buserr smbpecerr smbtout - - - nak 76 5 43210 orun urun - - tcomp - txrdy rxrdy
468 32072d?04/2011 at32uc3a3/a4 22.9.10 interrupt mask register name: imr access type: read-only offset :0x24 reset value: 0x00000000 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. this bit is cleared when the corresponding bit in idr is written to one. this bit is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 -- - ----- 23 22 21 20 19 18 17 16 btf rep sto smbdam smbhhm smbalertm gcm sam 15 14 13 12 11 10 9 8 - buserr smbpecerr smbtout - - - nak 76 5 43210 orun urun - - tcomp - txrdy rxrdy
469 32072d?04/2011 at32uc3a3/a4 22.9.11 status clear register name: scr access type: write-only offset :0x28 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in sr and the corresponding interrupt request. 31 30 29 28 27 26 25 24 - 23 22 21 20 19 18 17 16 btf rep sto smbdam smbhhm smbalertm gcm sam 15 14 13 12 11 10 9 8 - buserr smbpecerr smbtout - - - nak 76 5 43210 orun urun - - tcomp - - -
470 32072d?04/2011 at32uc3a3/a4 22.9.12 parameter register name: pr access type: read-only offset :0x2c reset value: 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------
471 32072d?04/2011 at32uc3a3/a4 22.9.13 version register (vr) name: vr access type: read-only offset: 0x30 reset value: device-specific ? variant: variant number reserved. no functionality associated. ? version: version number version number of the module. no functionality associated. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ---- variant 15 14 13 12 11 10 9 8 ---- version [11:8] 76543210 version [7:0]
472 32072d?04/2011 at32uc3a3/a4 22.10 module configuration the specific configuration for each twis instance is listed in the following tables.the module bus clocks listed here are connected to the system bus clocks according to the table in the power manager section. table 22-7. module clock name module name clock name twis0 clk_twis0 twis1 clk_twis1 table 22-8. register reset values register reset value vr 0x00000100 pr 0x00000000
473 32072d?04/2011 at32uc3a3/a4 23. two-wire master interface (twim) rev: 1.0.0.1 23.1 features ? compatible with i 2 c standard ? multi-master support ? 100 and 400 kbit/sin transfer speed ? 7- and 10-bit and general call addressing ? compatible with smbus standard ? hardware packet error checking (crc) ge neration and verification with ack control ? smbus alert interface ? 25 ms clock low timeout delay ? 10 ms master cumulative clock low extend time ? 25 ms slave cumulative clock low extend time ? compatible with pmbus ? compatible with atmel two-wi re interface se rial memories ? dma interface for reducing cpu load ? arbitrary transfer lengths, including 0 data bytes ? optional clock stretching if transmit or receive buffers not ready for data transfer 23.2 overview the atmel two-wire interface master (twim) interconnects components on a unique two-wire bus, made up of one clock line and one data line with speeds of up to 400 kbit/s, based on a byte-oriented transfer format. it can be used with any atmel two-wire interface bus serial eeprom and i2c compatible device such as a r eal rime clock (rtc), dot matrix/graphic lcd controller and temperature sensor, to name a few. twim is always a bus master and can trans- fer sequential or single bytes. multiple master capability is supported. arbitration of the bus is performed internally and relinquishes the bus automatically if the bus arbitration is lost. a configurable baud rate generator permits the output data rate to be adapted to a wide range of core clock frequencies. table 23-1 on page 473 lists the compatibility le vel of the atmel two-wire interface in master mode and a full i2c compatible device. note: 1. start + b000000001 + ack + sr table 23-1. atmel twim compatib ility with i2c standard i2c standard atmel twim standard-mode (100 kbit/s) supported fast-mode (400 kbit/s) supported fast-mode plus (1 mbit/s) supported 7- or 10-bits slave addressing supported start byte (1) not supported repeated start (sr) condition supported ack and nack management supported slope control and input filtering (fast mode) supported clock stretching supported
474 32072d?04/2011 at32uc3a3/a4 table 23-2 on page 474 lists the compatibility level of the atmel two-wire master interface and a full smbus compatible master. 23.3 list of abbreviations table 23-2. atmel twim compatibilit y with smbus standard smbus standard atmel twim bus timeouts supported address resolution protocol supported alert supported host functionality supported packet error checking supported table 23-3. abbreviations abbreviation description twi two-wire interface a acknowledge na non acknowledge pstop sstart sr repeated start sadr slave address adr any address except sadr r read wwrite
475 32072d?04/2011 at32uc3a3/a4 23.4 block diagram figure 23-1. block diagram 23.5 application block diagram2 figure 23-2. application block diagram 23.6 i/o lines description peripheral bus bridge two-wire interface i/o controller twck twd intc twi interrupt power manager clk_twim twalm twi master twd twck atmel twi serial eeprom i 2 c rtc i 2 c lcd controller i 2 c temp sensor slave 2slave 3slave 4 vdd rp rp rp: pull-up value as given by the i2c standard twalm slave 1 rp table 23-4. i/o lines description pin name pin description type twd two-wire serial data input/output twck two-wire serial clock input/output twalm smbus smbalert input/output
476 32072d?04/2011 at32uc3a3/a4 23.7 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 23.7.1 i/o lines twd and twck are bidirectional lines, connected to a positive supply voltage via a current source or pull-up resistor (see figure 23-4 on page 477 ). when the bus is free, both lines are high. the output stages of devices connected to the bus must have an open-drain or open-col- lector to perform the wired-and function. twalm is used to implement the optional smbus smbalert signal. the twalm, twd, and twck pins may be multip lexed with i/o controller lines. to enable the twim, the programmer must perform the following steps: ? program the i/o controller to: ? dedicate twd, twck and optionally twalm as peripheral lines. ? define twd, twck and optionally twalm as open-drain. 23.7.2 power management if the cpu enters a sleep mode th at disables clocks used by t he twim, the twim will stop func- tioning and resume operation after the system wakes up from sleep mode. 23.7.3 clocks the clock for the twim bus interface (clk_twim) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to dis- able the twim before disabling the clock, to avoid freezing the twim in an undefined state. 23.7.4 dma the twim dma handshake interface is connected to the peripheral dma controller. using the twim dma functionality requires the peripheral dma controller to be programmed after setting up the twim. 23.7.5 interrupts the twim interrupt request lines are connected to the interrupt controller. using the twim inter- rupts requires the interrupt controller to be programmed first. 23.7.6 debug operation when an external debugger forces the cpu into debug mode, the twim continues normal oper- ation. if the twim is configured in a way that requires it to be periodically serviced by the cpu through interrupts or similar, improper operation or data loss may result during debugging.
477 32072d?04/2011 at32uc3a3/a4 23.8 functional description 23.8.1 transfer format the data put on the twd line must be 8 bits long. data is transferred msb first; each byte must be followed by an acknowledgement. the number of bytes per transfer is unlimited (see figure 23-4 on page 477 ). each transfer begins with a start condition and terminates with a stop condition (see figure 23-4 on page 477 ). ? a high-to-low transition on the twd line while twck is high defines the start condition. ? a low-to-high transition on the twd line while twck is high defines a stop condition. figure 23-3. start and stop conditions figure 23-4. transfer format 23.8.2 operation the twim has two modes of operation: ? master transmitter mode ? master receiver mode the master is the device which starts and stops a transfer and generates the twck clock. these modes are described in the following chapters. twd twck start stop twd twck start address r/w ack data ack data ack stop
478 32072d?04/2011 at32uc3a3/a4 23.8.2.1 clock generation the the clock waveform generator register (cwgr) is used to control the waveform of the twck clock. cwgr must be programmed so that the desired twi bus timings are generated. cwgr describes bus timings as a function of cycles of a prescaled clock. the clock prescaling can be selected through the exp field in cwgr. cwgr has the following fields: low: prescaled clock cycles in cl ock low count. used to time t low . and t buf . high: prescaled clock cycles in cl ock high count. used to time t high . stasto: prescaled clock cycles in cl ock high count. used to time t hd_sta , t su_sta , t su_sto . data: prescaled clock cycles for data setu p and hold count. used to time t hd_dat , t su_dat . exp: specifies the clo ck prescaler setting. note that the total clock low time generated is the sum of t hd_dat + t su_dat + t low . any slave or other bus master taking part in the transfer may extend the twck low period at any time. the twim hardware monitors the state of the tw ck line as required by the i2c specification. the clock generation counters are started when a high/low level is detected on the twck line, not when the twim hardware releases/drives the twck line. this means that the cwgr set- tings alone do not determine the twck frequency. the cwgr settings determine the clock low time and the clock high time, but the twck rise a nd fall times are determined by the external cir- cuitry (capacitive load, etc.). figure 23-5. bus timing diagram f prescaled f clkpb 2 exp 1 + ) () ------------------------- - = s t hd:sta t low t su:dat t high t hd:dat t low p t su:sto sr t su:sta t su:dat
479 32072d?04/2011 at32uc3a3/a4 23.8.2.2 setting up and performing a transfer operation of twim is mainly controlled by the control register (cr) and the command register (cmdr). the following list presents the ma in steps in a typical communication: 1. before any transfers can be performed, bus timings must be configured by program- ming the clock waveform generator register (cwgr). if operating in smbus mode, the smbus timing register (smbtr) register must also be configured. 2. if a dma controller is to be used for the transfers, it must be set up. 3. cmdr or ncmdr must be programmed with a value describing the transfer to be performed. the interrupt system can be set up to give interr upt request on specific events or error condi- tions, for example when the transfer is complete or if arbitration is lost. the controller will refuse to star t a new transfer while anak, dnak or arblst is set in the sta- tus register (sr). this is necessary to avoid a race when the software issues a continuation of the current transfer at the same time as one of these errors happen. also, if anak or dnak occur, a stop condition is sent automatically. the programmer will have to restart the transmis- sion by clearing the errors bit in sr after resolving the cause for the nack. after a data or address nack from the slave, a stop will be transmitted automatically. note that the valid bit in cmdr is not cleared in this case. if this transfer is to be discarded, the valid bit can be cleared manually allowing any command in ncmdr to be copied into cmdr. when a data or address nack is returned by the slave while the master is transmitting, it is pos- sible that new data has already been written to th e thr register. this data will be tran sferred out as the first data byte of the next transfer. if this behavior is to be avoided, the safest approach is to perform a software reset of the twim. 23.8.3 master transmitter mode a start condition is transmitted and master trans mitter mode is initiated when the bus is free and cmdr has been written with start=1 and read=0. start and sadr+w will then be transmitted. during the address acknowledge clock pulse (9th pulse), the master releases the data line (high), enabling the slave to pull it down in order to acknowledge the address. the master polls the data line during this clock pulse and sets the address not acknowledged bit (anak ) in the status register if no slave acknowledges the address. after the address phase, the following is repeated: while (nbytes>0) 1. wait until thr contains a valid data byte, stretching low period of twck. sr.txrdy indicates the state of thr. software or a dma controller must write the data byte to thr. 2. transmit this data byte 3. decrement nbytes 4. if (nbytes==0) and stop=1, transmit stop condition programming cmdr with start=stop=1 and nbyt es=0 will generate a transmission with no data bytes, ie start, sadr+w, stop. twi transfers require the slave to acknowle dge each received data byte. during the acknowl- edge clock pulse (9th pulse), the master releases the data line (high), enabling the slave to pull it down in order to generate the acknowledge. t he master polls the data line during this clock pulse and sets the data acknowledge bit (dnack) in the status register if the slave does not
480 32072d?04/2011 at32uc3a3/a4 acknowledge the data byte. as with the other status bits, an interrupt can be generated if enabled in the interrupt enable register (twim_ier). txrdy is used as transmit ready for the pe ripheral dma controller transmit channel. the end of a command is marked by setting the sr.ccomp bit to one. see figure 23-6 on page 480 and figure 23-7 on page 480 . figure 23-6. master write with one data byte figure 23-7. master write with mu ltiple data bytes 23.8.4 master receiver mode a start condition is transmitted and master receiver mode is initiated when the bus is free and cmdr has been written with start=1 and read=1. start and sadr+r will then be trans- mitted. during the address acknowledge clock puls e (9th pulse), the master releases the data line (high), enabling the slave to pull it down in order to acknowledge the address. the master polls the data line during this clock pulse and sets the address not acknowledged bit (anak) in the status register if no slave acknowledges the address. after the address phase, the following is repeated: while (nbytes>0) 1. wait until rhr is empty, stretching low period of twck. sr.rxrdy indicates the state of rhr. software or a dma controller must read any data byte present in rhr. 2. release twck generating a clock that the slave uses to transmit a data byte. 3. place the received data byte in rhr, set rxrdy. 4. if nbytes=0, generate a nak after the data byte, otherwise generate an ack. 5. decrement nbytes twd sr.idle txrdy write thr (data) nbytes set to 1 stop sent automatically (ack received and nbytes=0) sdadr wa data ap twd sr.idle txrdy write thr (datan) nbytes set to n stop sent automatically (ack received and nbytes=0) sdadr wa datan a datan+5 aa datan+m p write thr (datan+1) write thr (datan+m) last data sent
481 32072d?04/2011 at32uc3a3/a4 6. if (nbytes==0) and stop=1, transmit stop condition. programming cmdr with start=stop=1 and nbyt es=0 will generate a transmission with no data bytes, ie start, dadr+r, stop the twi transfers require the master to a cknowledge each received data byte. during the acknowledge clock pulse (9th pulse), the slave releases the data line (high), enabling the mas- ter to pull it down in order to generate the acknowledge. all data bytes except the last are acknowledged by the master. not acknowledging the last byte informs the slave that the transfer is finished. rxrdy is used as receive ready for the peripheral dma controller receive channel. figure 23-8. master read with one data byte figure 23-9. master read with mu ltiple data bytes 23.8.5 using the peripheral dma controller the use of the peripheral dma controller signi ficantly reduces the cpu load. the programmer can set up ring buffers for the dma controller, containing data to transmit or free buffer space to place received data. to assure correct behavior, respect the following programming sequences: twd sr.idle rxrdy write start & stop bit nbytes set to 1 read rhr sdadr r a data np twd sr.idle rxrdy write start + stop bit nbytes set to m sdadr r a datan a datan+m-1 an datan+m p read rhr datan datan+1 read rhr datan+m-2 read rhr datan+m-1 read rhr datan+m send stop when nbytes=0
482 32072d?04/2011 at32uc3a3/a4 23.8.5.1 data transmit with the peripheral dma controller 1. initialize the transmit peripheral dma controller (memory pointers, size, etc.). 2. configure the twim (adr, nbytes, etc.). 3. start the transfer by setting the peripheral dma controller txten bit. 4. wait for the peripheral dma controller end tx flag. 5. disable the peripheral dma controller by se tting the peripheral dma controller txdis bit. 23.8.5.2 data receive with th e peripheral dma controller 1. initialize the receive peripheral dma controller (memory pointers, size, etc.). 2. configure the twim (adr, nbytes, etc.). 3. start the transfer by setting the peripheral dma controller rxten bit. 4. wait for the peripheral dma controller end rx flag. 5. disable the peripheral dma controller by setting the peripheral dma controller rxdis bit. 23.8.6 multi-master mode more than one master may access the bus at the same time without data corruption by using arbitration. arbitration starts as soon as two or more masters place information on the bus at the same time, and stops (arbitration is lost) for the master that intends to send a logical one while the other master sends a logical zero. as soon as arbitration is lost by a master, it st ops sending data and listens to the bus in order to detect a stop. the sr.arblst flag will be set. when the stop is detected, the master who lost arbitration may reinitiate the data transfer. arbitration is illustrated in figure 23-11 on page 483 . if the user starts a transfer and if the bus is busy, twim automatically waits for a stop condition on the bus before initiating the transfer (see figure 23-10 on page 482 ). note: the state of the bus (busy or free) is not indicated in the user interface. figure 23-10. programmer sends data while the bus is busy twck twd data sent by a master stop sent by the master start sent by the twi data sent by the twi bus is busy bus is free a transfer is programmed (dadr + w + start + write thr) transfer is initiated twi data transfer transfer is kept bus is considered as free
483 32072d?04/2011 at32uc3a3/a4 figure 23-11. arbitration cases 23.8.7 combined transfers cmdr and ncmdr may be used to generate longer sequences of connected transfers, since generation of start and/or stop conditions is programmable on a per-command basis. programming ncmdr with start=1 when the previous transfer was programmed with stop=0 will cause a repeated start on the bus. the ability to generate such connected transfers allows arbitrary transfer lengths, since it is legal to program cmdr with both start=0 and stop=0. if this is done in master receiver mode, the cmdr.acklast bit must also be controlled. as for single data transfers, the txrdy and rxrd y bits in the status register indicates when data to transmit can be written to the thr, or when received data can be read from rhr. trans- fer of data to thr and from rhr can also be done automatically by dma, see ?using the peripheral dma controller? on page 481 23.8.7.1 write followed by write consider the fo llowing transfer: start, dadr+w, data+a, data+a, repstart, dadr+w, data+a, data+a, stop. to generate this transfer: 1. program cmdr with start=1, stop=0, dadr, nbytes=2 and read=0. 2. program ncmdr with start=1, st op=1, dadr, nbytes=2 and read=0. 3. wait until sr.txrdy==1, then write first data byte to transfer to thr. 4. wait until sr.txrdy==1, then write second data byte to transfer to thr. twck bus is busy bus is free a transfer is programmed (dadr + w + start + write thr) transfer is initiated twi data transfer transfer is kept bus is considered as free data from a master data from twi s 0 s 0 0 1 1 1 arblst s 0 s 0 0 1 1 1 twd s 0 0 1 1 1 1 1 arbitration is lost twi stops sending data p s 0 1 p 0 1 1 1 1 data from the master data from the twi arbitration is lost the master stops sending data transfer is stopped transfer is programmed again (dadr + w + start + write thr) twck twd
484 32072d?04/2011 at32uc3a3/a4 5. wait until sr.txrdy==1, then write third data byte to transfer to thr. 6. wait until sr.txrdy==1, then write fourth data byte to transfer to thr. 23.8.7.2 read followed by read consider the fo llowing transfer: start, dadr+r, data+a, data+na, repstart, dadr+r, data+a, data+na, stop. to generate this transfer: 1. program cmdr with start=1, stop=0, dadr, nbytes=2 and read=1. 2. program ncmdr with start=1, st op=1, dadr, nbytes=2 and read=1. 3. wait until sr.rxrdy==1, then read first data byte received from rhr. 4. wait until sr.rxrdy==1, then read second data byte received from rhr. 5. wait until sr.rxrdy==1, then read third data byte received from rhr. 6. wait until sr.rxrdy==1, then read fourth data byte received from rhr. if combining several tr ansfers, without any stop or repeated start between them, remem- ber to set the acklast bit in cmdr to keep from ending each of the partial transfers with a nack. 23.8.7.3 write followed by read consider the fo llowing transfer: start, dadr+w, data+a, data+a, repstart, dadr+r, data+a, data+na, stop. figure 23-12. combining a write and read transfer to generate this transfer: 1. program cmdr with start=1, stop=0, dadr, nbytes=2 and read=0. 2. program ncmdr with start=1, st op=1, dadr, nbytes=2 and read=1. 3. wait until sr.txrdy==1, then write first data byte to transfer to thr. 4. wait until sr.txrdy==1, then write second data byte to transfer to thr. 5. wait until sr.rxrdy==1, then read first data byte received from rhr. 6. wait until sr.rxrdy==1, then read second data byte received from rhr. 23.8.7.4 read followed by write consider the fo llowing transfer: start, dadr+r, data+a, data+na, repstart, dadr+w, data+a, data+a, stop. twd sr.idle txrdy sdadr wa data0 a data1 na sr dadr r a data2 a data3 a p data0 data1 thr rxrdy 1 rhr data3 data2
485 32072d?04/2011 at32uc3a3/a4 figure 23-13. combining a read and write transfer to generate this transfer: 1. program cmdr with start=1, stop=0, dadr, nbytes=2 and read=1. 2. program ncmdr with start=1, st op=1, dadr, nbytes=2 and read=0. 3. wait until sr.rxrdy==1, then read first data byte received from rhr. 4. wait until sr.rxrdy==1, then read second data byte received from rhr. 5. wait until sr.txrdy==1, then write first data byte to transfer to thr. 6. wait until sr.txrdy==1, then write second data byte to transfer to thr. 23.8.8 ten bit addressing setting cmdr.tenbit enables 10-bit addressing in hardware. performing transfers with 10-bit addressing is similar to transfers with 7-bit addresses, except that bits 10:7 of cmdr.adr must be set appropriately. in figure 23-14 on page 485 and figure 23-15 on page 486 , the grey boxes represent signals driven by the master, the white boxes are driven by the slave. 23.8.8.1 master transmitter to perform a master transmitter transfer, 1. program cmdr with tenbit=1, repsame=0, read=0, start=1, stop=1 and the desired address and nbytes value. figure 23-14. a write transfer with 10-bit addressing 23.8.8.2 master receiver when using master receiver mode with 10-bit addressing, cm dr.repsame must also be con- trolled. cmdr.repsame must be written to one when the address phase of the transfer should consist of only 1 address byte (the 11110xx byte) and not 2 address bytes. the i2c standard specifies that such addressing is required wh en addressing a slave for reads using 10-bit addressing. to perform a master receiver transfer, twd sr.idle txrdy ssadr r a data0 a data1 sr dadr w a data2 a data3 na p data2 thr rxrdy rhr data3 data0 a 1 2 data3 read twi_rhr s slave address 1st 7 bits p a data rw a1 a2 slave address 2nd byte aa data 11110xx0
486 32072d?04/2011 at32uc3a3/a4 1. program cmdr with tenbit=1, repsam e=0, read=0, start=1, stop=0, nbytes=0 and the desired address. 2. program ncmdr with tenbit=1, repsame=1, read=1, start=1, stop=1 and the desired address and nbytes value. figure 23-15. a read transfer with 10-bit addressing 23.8.9 smbus mode smbus mode is enabled and disabled by the smen and smdis bits in cr. smbus mode oper- ation is similar to i2c operation with the following exceptions: ? only 7-bit addressing can be used. ? the smbus standard describes a set of timeout values to ensure progress and throughput on the bus. these timeout values must be programmed into smbtr. ? transmissions can optionally include a crc byte, called packet error check (pec). ? a dedicated bus line, smbalert, allows a slave to get a master?s attention. ? a set of addresses have been reserved for protocol handling, such as alert response address (ara) and host header (hh) address. 23.8.9.1 packet error checking each smbus transfer can optionally end with a crc byte, called the pec byte. writing cmdr.pecen to one enables automatic pec handling in the current transfer. transfers with and without pec can freely be intermixed in the same system, since some slaves may not sup- port pec. the pec lfsr is always updated on every bit transmitted or received, so that pec handling on combined transfers will be correct. in master transmitter mode, the master calculates a pec value and transmits it to the slave after all data bytes have been transm itted. upon reception of this pec byte, the slave will compare it to the pec value it has computed itself. if the values match, the data was received correctly, and the slave will return an ack to th e master. if the pec values differ, data was corrupted, and the slave will return a nack value. the dnak bit in sr reflects the state of the last received ack/nack value. some slaves may not be able to check the received pec in time to return a nack if an error occurred. in this case, the slave should always retu rn an ack after the pec byte, and some other mechanism must be implemented to verify that the transmission was received correctly. in master receiver mode, the slave calculates a pec value and transmits it to the master after all data bytes have been transmitted. upon reception of this pec by te, the master will compare it to the pec value it has computed itself. if the values match, the data was received correctly. if the pec values differ, data was corrupted, and the pecerr bit in sr is set. in master receiver mode, the pec byte is always followed by a nack transmitted by the master, since it is the last byte in the transfer. the pec byte is automatically inserted in a master transmitter transmission if pec is enabled when nbytes reaches zero. the pec byte is identified in a master receiver transmission if pec is enabled when nbytes reaches zero. nbytes must therefore be set to the total num- ber of data bytes in the transmission, including the pec byte. s slave address 1st 7 bits p a data rw a1 a2 slave address 2nd byte a data 11110xx0 sr slave address 1st 7 bits rw a3 11110xx1
487 32072d?04/2011 at32uc3a3/a4 in combined transfers, the pecen bit should only be set in the last of the combined transfers. consider the fo llowing transfer: s, adr+w, command_byte, ack, sr, adr+ r, data_byte, ack, pec_byte, nack, p this transfer is generated by writing two commands to the command registers. the first com- mand is a write with nbytes=1 and pecen=0, and the second is a read with nbytes=2 and pecen=1. writing a one to the stop bit in cr will pl ace a stop condition on the bus after the current byte. no pec byte will be sent in this case. 23.8.9.2 timeouts the tlows and tlowm fields in smbtr confi gure the smbus timeout values. if a timeout occurs, the master will transmit a stop condition and leave the bus. the sr.tout bit is also set. 23.8.9.3 smbus alert signal a slave can get the master?s attention by pu lling the twalm line low. sr.smbal will then be set. this can be set up to trigger an interrupt, and software can then take the appropriate action, as defined in the smbus standard. 23.8.10 identifying bus events this chapter lists the different bus events, and how these affects bits in the twim registers. this is intended to help writing drivers for the twim. table 23-5. bus events event effect master transmitter has sent a data byte sr.thr is cleared. master receiver has received a data byte sr.rhr is set. start+sadr sent, no ack received from slave sr.anak is set. sr.ccomp not set. cmdr.valid remains set. stop automatically transmitted on bus. data byte sent to slave, no ack received from slave sr.dnak is set. sr.ccomp not set. cmdr.valid remains set. stop automatically transmitted on bus. arbitration lost sr.arblst is set. sr.ccomp not set. cmdr.valid remains set. twck and twd immediately released to a pulled-up state. smbus alert received sr.smbal is set. smbus timeout received sr.smbtout is set. sr.ccomp not set. cmdr.valid remains set. stop automatically transmitted on bus.
488 32072d?04/2011 at32uc3a3/a4 master transmitter receives smbus pec error sr.dnak is set. sr.ccomp not set. cmdr.valid remains set. stop automatically transmitted on bus. master receiver discovers smbus pec error sr.pecerr is set. sr.ccomp not set. cmdr.valid remains set. stop automatically transmitted on bus. cr.stop is written by user sr.stop is set. sr.ccomp set. cmdr.valid remains set. stop transmitted on bus after curr ent byte transfer has finished. table 23-5. bus events event effect
489 32072d?04/2011 at32uc3a3/a4 23.9 user interface note: 1. the reset values for these registers are device specific. please refer to the module configuration section at the end of this chapter. table 23-6. twim register memory map offset register register name access reset 0x00 control cr write-only 0x00000000 0x04 clock waveform generator cwgr read/write 0x00000000 0x08 smbus timing smbtr read/write 0x00000000 0x0c command cmdr read/write 0x00000000 0x10 next command ncmdr read/write 0x00000000 0x14 receive holding rhr read-only 0x00000000 0x18 transmit holding thr write-only 0x00000000 0x1c status sr read-only 0x00000002 0x20 interrupt enable register ier write-only 0x00000000 0x24 interrupt disable register idr write-only 0x00000000 0x28 interrupt mask register imr read-only 0x00000000 0x2c status clear register scr write-only 0x00000000 0x30 parameter register pr read-only (1) 0x34 version register vr read-only (1)
490 32072d?04/2011 at32uc3a3/a4 23.9.1 control register (cr) name: cr access type: write-only offset: 0x00 reset value: 0x00000000 ? stop: stop the current transfer writing a one to this bit terminates the current transfer, sendi ng a stop condition after the shifter has become idle. if there are additional pending transfers, they will have to be explicitly re started by software after the stop condition has been successfu lly sent. writing a zero to this bit has no effect. ? swrst: software reset if the twim master interface is enabled, writing a one to this bit resets the twim. all transfers are halted immediately, possi bly violating the bus semantics. if the twim master interface is not enabled, it must first be enabled before writing a one to this bit. writing a zero to this bit has no effect. ? smdis: smbus disable writing a one to this bit disables smbus mode. writing a zero to this bit has no effect. ? smen: smbus enable writing a one to this bit enables smbus mode. writing a zero to this bit has no effect. ? mdis: master disable writing a one to this bit disables the master interface. writing a zero to this bit has no effect. ? men: master enable writing a one to this bit enables the master interface. writing a zero to this bit has no effect. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------stop 76543210 swrst - smdis smen - - mdis men
491 32072d?04/2011 at32uc3a3/a4 23.9.2 clock waveform generator register (cwgr) name: cwgr access type: read/write offset: 0x04 reset value: 0x00000000 ? exp: clock prescaler used to specify how to prescale the twck clock. coun ters are prescaled according to the following formula ? data: data setu p and hold cycles clock cycles for data setup and hold count. prescaled by cwgr.exp . used to time t hd_dat , t su_dat . ? stasto: start and stop cycles clock cycles in clock high count. prescaled by cwgr.exp. used to time t hd_sta , t su_sta , t su_sto ? high: clock high cycles clock cycles in clock high count. prescaled by cwgr.exp. used to time t high . ? low: clock low cycles clock cycles in clock low count. pre scaled by cwgr.exp. used to time t low , t buf . 31 30 29 28 27 26 25 24 - exp data 23 22 21 20 19 18 17 16 stasto 15 14 13 12 11 10 9 8 high 76543210 low f prescaled f clkpb 2 exp 1 + () ----------------------- - =
492 32072d?04/2011 at32uc3a3/a4 23.9.3 smbus timing register (smbtr) name: smbtr access type: read/write offset: 0x08 reset value: 0x00000000 ? exp: smbus timeout clock prescaler used to specify how to prescale the ti m and tlowm counters in smbtr. counters are prescaled according to the following formula ? thmax: clock high maximum cycles clock cycles in clock high maximum count. prescaled by smbtr.exp. used for bus free de tection. used to time t high:max . note: uses the prescaler specified by cw gr, not the prescaler specified by smbtr. ? tlowm: master clock stretch maximum cycles clock cycles in master maximum clock stretch count. prescaled by smbtr.exp. used to time t low:mext ? tlows: slave clock stretch maximum cycles clock cycles in slave maximum clock stretch coun t. prescaled by smbtr.exp. used to time t low:sext . 31 30 29 28 27 26 25 24 exp ---- 23 22 21 20 19 18 17 16 thmax 15 14 13 12 11 10 9 8 tlowm 76543210 tlows f prescaled smbus , f clkpb 2 exp 1 + () ----------------------- - =
493 32072d?04/2011 at32uc3a3/a4 23.9.4 command register (cmdr) name: cmdr access type: read/write offset: 0x0c reset value: 0x00000000 ? acklast: ack last master rx byte writing this bit to zero causes the last byte in master re ceive mode (when nbytes has reached 0) to be nacked. this is the standard way of ending a master receiver transfer. writing this bit to one causes the last byte in master rece ive mode (when nbytes has reached 0) to be acked. used for performing linked transfers in master re ceiver mode with no stop or repeated start between the subtransfers. this is needed when more than 255 bytes are to be received in one single transmission. ? pecen: packet error checking enable writing this bit to zero causes the transfer not to use pec by te verification. the pec lfsr is still updated for every bit transmitted or received. must be used if smbus mode is disabled. writing this bit to one causes the transfer to use pec. pec byte generation (if master transmitter) or pec byte verification (i f master receiver) will be performed. ? nbytes: number of data bytes in transfer the number of data bytes in the transfer. after the specified number of bytes have been transferred, a stop condition is transmitted if cmdr.stop is set. in smbus mode, if pec is used, nbytes includes the pec byte, ie there are nbytes-1 data bytes and a pec byte. ? valid: cmdr valid writing this to zero indicates that cmdr does not contain a valid command. writing this to one indicates that cmdr contains a valid command. this bit is cleared when the command is finished. ? stop: send stop condition write this bit to zero to not transmit a stop condition after the data bytes have been transmitted. write this bit to one to transmit a stop condition after the data bytes have been transmitted. ? start: send start condition write this bit to zero if the transfer in cmdr should not commence with a start or repeated start condition. write this bit to one if the transfer in cmdr should commence with a start or repeate d start condition. if the bus is free when the command is execut ed, a start condition is us ed, if the bus is busy, a repeated start is used. ? repsame: transfer is to same address as previous address only used in 10-bit addressing mode, always write to 0 in 7-bit addressing mode. 31 30 29 28 27 26 25 24 - -- - -- acklast pecen 23 22 21 20 19 18 17 16 nbytes 15 14 13 12 11 10 9 8 valid stop start repsame tenbit sadr[9:7] 76543210 sadr[6:0] read
494 32072d?04/2011 at32uc3a3/a4 write this bit to one if the command in cmdr performs a repeated start to the same slave address as addressed in the previous transfer in order to enter master receiver mode. write this bit to zero otherwise. ? tenbit: ten bit addressing mode write this bit to zero to use 7-bit addressing mode. write this bit to one to use 10-bit addressing mode. must not be used when twim is in smbus mode. ? sadr: slave address address of the slave involved in the transfer. bi ts 9-7 are don?t care if 7-bit addressing is used. ? read: transfer direction write this bit to zero to let the master transmit data. write this bit to one to le t the master receive data.
495 32072d?04/2011 at32uc3a3/a4 23.9.5 next command register (ncmdr) name: ncmdr access type: read/write offset: 0x10 reset value: 0x00000000 this register is identical to cmdr. when the valid bit in cmdr becomes 0, the contents of ncmdr is copied into cmdr, clearing the valid bit in ncmdr. if the valid bit in cmdr is cleared when ncmdr is written, the contents are copied immediately. 31 30 29 28 27 26 25 24 - --- - --- acklast pecen 23 22 21 20 19 18 17 16 nbytes 15 14 13 12 11 10 9 8 valid stop start repsame tenbit sadr[9:7] 76543210 sadr[6:0] read
496 32072d?04/2011 at32uc3a3/a4 23.9.6 receive holding register (rhr) name: rhr access type: read-only offset: 0x14 reset value: 0x00000000 ? rxdata: received data when the rxrdy bit in the status regist er (sr) is set, this field contains a byte received from the twi bus. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 rxdata
497 32072d?04/2011 at32uc3a3/a4 23.9.7 transmit holding register (thr) name: thr access type: write-only offset: 0x18 reset value: 0x00000000 ? txdata: data to transmit write data to be transf erred on the twi bus here. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 txdata
498 32072d?04/2011 at32uc3a3/a4 23.9.8 status register (sr) name: sr access type: read-only offset: 0x1c reset value: 0x00000002 ? menb: master interface enable 0: master interface is disabled. 1: master interface is enabled. ? stop: stop request accepted this bit is set when stop request caused by sett ing cr stop has been accepted, and transfer has stopped. this bit is cleared by writing 1 to the corresp onding bit in the status clear register (scr). ? pecerr: pec error this bit is set when a smbus pec error occurred. this bit is cleared by writing 1 to the corresp onding bit in the status clear register (scr). ?tout: timeout this bit is set when a smbus timeout occurred. this bit is cleared by writing 1 to the corresp onding bit in the status clear register (scr). ? smbalert: smbus alert this bit is set when an smbus alert was received. this bit is cleared by writing 1 to the corresp onding bit in the status clear register (scr). ? arblst: arbitration lost this bit is set when the actual state of the sda line did not correspond to the data driven onto it, indicating a higher-priori ty transmission in progress by a different master. this bit is cleared by writing 1 to the corresp onding bit in the status clear register (scr). ? dnak: nak in data phase received this bit is set when no ack was received form slave during data transmission. this bit is cleared by writing 1 to the corresp onding bit in the status clear register (scr). ? anak: nak in address phase received this bit is set when no ack was received from slave during address phase this bit is cleared by writing 1 to the correspo nding bit in the status clear register (scr). ? busfree: two-wire bus is free this bit is set when activity has completed on the two-wire bus. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------menb 15 14 13 12 11 10 9 8 - stop pecerr tout smbalert arblst dnak anak 76543210 - - busfree idle ccomp crdy txrdy rxrdy
499 32072d?04/2011 at32uc3a3/a4 otherwise, this bit is cleared. ? idle: master interface is idle this bit is set when no command is in progress, and no command waiting to be issued. otherwise, this bit is cleared. ? ccomp: command complete this bit is set when the current command has completed successfully. not set if the command failed due to conditions such as a nak receved from slave. this bit is cleared by writing 1 to the corresp onding bit in the status clear register (scr). ? crdy: ready for more commands this bit is set when cmdr and/or ncmdr is ready to receive one or more commands. this bit is cleared when this is no longer true. ? txrdy: thr data ready this bit is set when thr is ready for one or more data bytes. this bit is cleared when this is no longer tr ue (i.e. thr is full or transmission has stopped). ? rxrdy: rhr data ready this bit is set when rx data are ready to be read from rhr. this bit is cleared when this is no longer true.
500 32072d?04/2011 at32uc3a3/a4 23.9.9 interrupt enable register (ier) name: ier access type: write-only offset: 0x20 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will set the corresponding bit in imr 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - pecerr tout smbalert arblst dnak anak 76543210 - - busfree idle ccomp crdy txrdy rxrdy
501 32072d?04/2011 at32uc3a3/a4 23.9.10 interrupt disable register (idr) name: idr access type: write-only offset: 0x24 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in imr 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 --------- 15 14 13 12 11 10 9 8 - - pecerr tout smbalert arblst dnak anak 76543210 - - busfree idle ccomp crdy txrdy rxrdy
502 32072d?04/2011 at32uc3a3/a4 23.9.11 interrupt mask register (imr) name: imr access type: read-only offset: 0x28 reset value: 0x00000000 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. this bit is cleared when the corresponding bit in idr is written to one. this bit is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 --------- 15 14 13 12 11 10 9 8 - - pecerr tout smbalert arblst dnak anak 76543210 - - busfree idle ccomp crdy txrdy rxrdy
503 32072d?04/2011 at32uc3a3/a4 23.9.12 status clear register (scr) name: scr access type : write-only offset: 0x2c reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in sr and the corresponding interrupt request. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 --------- 15 14 13 12 11 10 9 8 - stop pecerr tout smbalert arblst dnak anak 76543210 ----ccomp---
504 32072d?04/2011 at32uc3a3/a4 23.9.13 parameter register (pr) name: pr access type: read-only offset: 0x30 reset value: 0x00000000 ? 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 --------
505 32072d?04/2011 at32uc3a3/a4 23.9.14 version register (vr) name: vr access type: read-only offset: 0x34 reset value: device-specific ? variant: variant number reserved. no functionality associated. ? version: version number version number of the module. no functionality associated. ? ? 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ---- variant 15 14 13 12 11 10 9 8 ---- version [11:8] 76543210 version [7:0]
506 32072d?04/2011 at32uc3a3/a4 23.10 module configuration the specific configuration for each twim inst ance is listed in the following tables.the module bus clocks listed here are connected to the system bus clocks according to the table in the power manager section. table 23-7. module clock name module name clock name twim0 clk_twim0 twim1 clk_twim1 table 23-8. register reset values register reset value vr 0x00000100 pr 0x00000000
507 32072d?04/2011 at32uc3a3/a4 24. synchronous serial controller (ssc) rev: 3.2.0.2 24.1 features ? provides serial synchronous communication li nks used in audio an d telecom applications ? independent receiver and transm itter, common clock divider ? interfaced with two peripher al dma controller channels to reduce processor overhead ? configurable frame sy nc and data length ? receiver and transmitter can be configured to start automatically or on detection of different events on the frame sync signal ? receiver and transmitter include a data signal, a cloc k signal and a frame synchronization signal 24.2 overview the synchronous serial controller (ssc) pr ovides a synchronous communication link with external devices. it supports many serial sy nchronous communication protocols generally used in audio and telecom applications such as i2s, short frame sync, long frame sync, etc. the ssc consists of a receiver, a transmitter, and a common clock divider. both the receiver and the transmitter interface with three signals: ? the tx_data/rx_data signal for data ? the tx_clock/rx_clock signal for the clock ? the tx_frame_sync/rx_frame_sync signal for the frame synchronization the transfers can be programmed to start automatically or on different events detected on the frame sync signal. the ssc?s high-level of programma bility and its two dedicated pe ripheral dma controller chan- nels of up to 32 bits permit a continuous hi gh bit rate data transfer without processor intervention. featuring connection to two peripheral dma cont roller channels, the ssc permits interfacing with low processor over head to the following: ? codec?s in master or slave mode ? dac through dedicated serial interface, particularly i2s ? magnetic card reader
508 32072d?04/2011 at32uc3a3/a4 24.3 block diagram figure 24-1. ssc block diagram 24.4 application block diagram figure 24-2. ssc application block diagram ssc interface peripheral dma control l er peripheral bus bridge hi gh speed bus peripheral bus power manager clk_ssc i/o controller interrupt control ssc interrupt tx_frame_sync rx_frame_ syn c tx_clock rx_clock rx_data tx_data test management line interface interrupt management frame management time slot management ssc power management codec serial audio os or rtos driver
509 32072d?04/2011 at32uc3a3/a4 24.5 i/o lines description 24.6 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 24.6.1 i/o lines the pins used for interfacing the compliant external devices may be multiplexed with i/o lines. before using the ssc receiver, the i/o controller must be configured to dedicate the ssc receiver i/o lines to the ssc peripheral mode. before using the ssc transmitter, the i/o controller must be configured to dedicate the ssc transmitter i/o lines to the ssc peripheral mode. 24.6.2 clocks the clock for the ssc bus interface (clk_ssc) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to disable the ssc before disabling the clock, to avoid freezing the ssc in an undefined state. 24.6.3 interrupts the ssc interrupt request line is connected to the interrupt controller. using the ssc interrupt requires the interrupt controller to be programmed first. 24.7 functional description this chapter contains the functional description of the following: ssc functional block, clock management, data framing format, start, transmitter, receiver, and frame sync. the receiver and the transmitter operate separately. however, they can work synchronously by programming the receiver to use the transmit clock and/or to start a data transfer when transmis- sion starts. alternatively, this can be done by programming the transmitter to use the receive clock and/or to start a data transfer when reception starts. the transmitter and the receiver can be programmed to operate with the clock signals provided on either the tx_clock or rx_clock pins. this allows the ssc to suppor t many slave-mode data transfers. the maxi- mum clock speed allowed on the tx_clock and rx_clock pins is clk_ssc divided by two. table 24-1. i/o lines description pin name pin description type rx_frame_sync receiver frame synchro input/output rx_clock receiver clock input/output rx_data receiver data input tx_frame_sync transmitter frame synchro input/output tx_clock transmitter clock input/output tx_data transmitter data output
510 32072d?04/2011 at32uc3a3/a4 figure 24-3. ssc functional block diagram 24.7.1 clock management the transmitter clock can be generated by: ? an external clock received on the tx_clock pin ? the receiver clock ? the internal clock divider the receiver clock can be generated by: ? an external clock received on the rx_clock pin ? the transmitter clock ? the internal clock divider furthermore, the transmitter block can generate an external clock on the tx_clock pin, and the receiver block can generate an external clock on the rx_clock pin. this allows the ssc to support many master and slave mode data transfers. clock divider user interface peripheral bus clk_ssc interrupt control start selector receive shift register receive holding register receive sync holding register dma interrupt controller rx_frame_sync rx_data rx_clock frame sync controller clock output controller receive clock controller transmit holding register transmit sync holding register transmit shift register frame sync controller clock output controller transmit clock controller start selector tx_frame_sync rx_frame_sync tx_clock input transmitter tx_dma load shift rx clock tx clock tx_clock tx_frame_sync tx_data receiver rx clock rx_clock input tx clock tx_frame_sync rx_frame_sync rx_dma load shift
511 32072d?04/2011 at32uc3a3/a4 24.7.1.1 clock divider figure 24-4. divided clock block diagram the peripheral clock divider is determined by th e 12-bit clock divider field (its maximal value is 4095) in the clock mode register (cmr.div), allo wing a peripheral clock division by up to 8190. the divided clock is provided to both the receiver and transmitter. when this field is written to zero, the clock divider is not used and remains inactive. when cmr.div is written to a value equal to or greater than one, the divided clock has a fre- quency of clk_ssc divided by two times cmr.div. each level of the divided clock has a duration of the peripheral clock multiplied by cmr.div. this ens ures a 50% duty cycle for the divided clock regardless of whether the cmr.div value is even or odd. figure 24-5. divided clock generation 24.7.1.2 transmitter clock management the transmitter clock is generated from the receiver clock, the divider clock, or an external clock scanned on the tx_clock pin. the transmitter cl ock is selected by writing to the transmit clock selection field in the transmit clock mode register (tcmr.cks). the transmit clock can table 24-2. range of clock divider maximum minimum clk_ssc / 2 clk_ssc / 8190 cmr / 2 clk_ssc divided clock 12-bit counter clock divider clk_ssc divided clock div = 1 clk_ssc divided clock div = 3 divided clock frequency = clk_ssc/2 divided clock fr equency = clk_ssc/6
512 32072d?04/2011 at32uc3a3/a4 be inverted independently by writing a one to the transmit clock inversion bit in tcmr (tcmr.cki). the transmitter can also drive the tx_clock pin continuously or be limited to the actual data transfer, depending on the transmit clock output mode selection field in the tcmr register (tcmr.cko). the tcmr.cki bit has no effect on the clock outputs. writing 0b10 to the tcmr.cks field to select tx_clock pin and 0b001 to the tcmr.cko field to select continuous transmit clock can lead to unpredictable results. figure 24-6. transmitter clock management 24.7.1.3 receiver clock management the receiver clock is generated from the transmitte r clock, the divider clock, or an external clock scanned on the rx_clock pin. the receive clock is selected by writing to the receive clock selection field in the receive clock mode register (rcmr.cks). the receive clock can be inverted independently by writing a one to the receive clock inversion bit in rcmr (rcmr.cki). the receiver can also drive the rx_clock pin continuously or be limited to the actual data transfer, depending on the receive clock output mode selection field in the rcmr register (rcmr.cko). the rcmr.cki bit has no effect on the clock outputs. writing 0b10 to the rcmr.cks field to select rx_clock pin and 0b001 to the rcmr.cko field to select continuous receive clock can lead to unpredictable results. tx_clock receiver clock divider clock cko data transfer tri-state controller inv mux cks mux tri-state controller cki ckg transmitter clock clock output
513 32072d?04/2011 at32uc3a3/a4 figure 24-7. receiver clock management 24.7.1.4 serial clock ratio considerations the transmitter and the receiver can be programme d to operate with the clock signals provided on either the tx_clock or rx_clock pins. th is allows the ssc to support many slave-mode data transfers. in this case, the maximum clock speed allowed on the rx_clock pin is: ? clk_ssc divided by two if rx_frame_sync is input. ? clk_ssc divided by three if rx_frame_sync is output. in addition, the maximum clock spe ed allowed on the tx_clock pin is: ? clk_ssc divided by six if tx_frame_sync is input. ? clk_ssc divided by two if tx_frame_sync is output. 24.7.2 transmitter operations a transmitted frame is triggered by a start event and can be followed by synchronization data before data transmission. the start event is configured by writing to the tcmr register. see section 24.7.4 . the frame synchronization is configured by writing to the transmit frame mode register (tfmr). see section 24.7.5 . to transmit data, the transmitter uses a shift re gister clocked by the transmitter clock signal and the start mode selected in the tcmr register. data is written by the user to the transmit holding register (thr) then transferred to the shift register according to the data format selected. when both the thr and the transmit shift registers are empty, the transmit empty bit is set in the status register (sr.txempty). when the thr register is transferred in the transmit shift register, the transmit ready bit is set in the sr register (sr.txready) and additional data can be loaded in the thr register. divider clock rx_clock transmitter clock mux tri-state controller cko data transfer inv mux cki tri-state controller ckg receiver clock clock output cks
514 32072d?04/2011 at32uc3a3/a4 figure 24-8. transmitter block diagram 24.7.3 receiver operations a received frame is triggered by a start event and can be followed by synchronization data before data transmission. the start event is configured by writing to the rcmr register. see section 24.7.4 . the frame synchronization is configured by wr iting to the receive frame mode register (rfmr). see section 24.7.5 . the receiver uses a shift register clocked by the receiver clock signal and the start mode selected in the rcmr register. the data is transferred from the shift register depending on the data format selected. when the receiver shift register is full, the ssc transfers this da ta in the receive holding regis- ter (rhr), the receive ready bit is set in the sr register (sr.rxready) and the data can be read in the rhr register. if another transfer occurs before a read of the rhr register , the receive overrun bit is set in the sr register (sr. ovrun) and the receiver shift register is trans- ferred to the rhr register. tfmr.datdef tfmr.msbf 0 1 transmit shift register 01 thr tshr tfmr.fslen tcmr.sttdly tfmr.fsden tfmr.datnb cr.txen cr.txdis sr.txen tx_data tfmr.datlen tcmr.sttdly tfmr.fsden start selector rx_frame_sync tx_frame_sync transmitter clock
515 32072d?04/2011 at32uc3a3/a4 figure 24-9. receiver block diagram 24.7.4 start the transmitter and receiver can both be programmed to start their operations when an event occurs, respectively in the transmit start selection field of the tcmr register (tcmr.start) and in the receive start selection field of the rcmr register (rcmr.start). under the following conditions the start event is independently programmable: ? continuous: in this case, the transmission starts as soon as a word is written to the thr register and the reception starts as soon as the receiver is enabled ? synchronously with the transmitter/receiver ? on detection of a falling/rising ed ge on tx_frame_sync/rx_frame_sync ? on detection of a low/high level on tx_frame_sync/rx_frame_sync ? on detection of a level change or an edge on tx_frame_sync/rx_frame_sync a start can be programmed in the same manner on either side of the transmit/receive clock mode register (tcmr/rcmr). thus, the start could be on tx_frame_sync (transmit) or rx_frame_sync (receive). moreover, the receiver can start when data is detected in the bit stream with the compare func- tions. see section 24.7.6 for more details on receive compare modes. detection on tx_frame_sync input/output is done by the transmit frame sync output selection field in the tfmr register (tfmr. fsos). similarly, detection on rx_frame_sync input/output is done by the receive frame output sync selection field in the rfmr register (rfmr.fsos). divider clock rx_clock transmitter clock mux tri-state controller cko data transfer inv mux cki tri-state controller ckg receiver clock clock output cks
516 32072d?04/2011 at32uc3a3/a4 figure 24-10. transmit start mode figure 24-11. receive pulse/ed ge start modes xb0b1 b1 b0 b0 b1 b1 b0 b0 b1 b0 b1 b0 b1 b1 b0 x x x x x tx_data (output) start= any edge on tx_frame_sync tx_data (output) start= level change on tx_frame_sync tx_data (output) start= rising edge on tx_frame_sync tx_data (output) start= falling edge on tx_frame_sync tx_data (output) start= high level on tx_frame_sync tx_data (output) start= low level on tx_frame_sync tx_frame_sync (input) tx_clock (input) sttdly sttdly sttdly sttdly sttdly sttdly rx_clock rx_frame_sync (input) rx_data (input) start = high level on rx_frame_sync rx_data (input) start = falling edge on rx_frame_sync rx_data (input) start = rising edge on rx_frame_sync rx_data (input) start = level change on rx_frame_sync rx_data (input) start = any edge on rx_frame_sync rx_data (input) start = low level on rx_frame_sync x x x x x xb0 b0 b0 b0 b0 b0 b0 b1 b1 b1 b1 b1 b1 b1 sttdly sttdly sttdly sttdly sttdly sttdly
517 32072d?04/2011 at32uc3a3/a4 24.7.5 frame sync the transmitter and receiver frame synchro pins, tx_frame_sync and rx_frame_sync, can be programmed to generate different kinds of frame synchronization signals. the rfmr.fsos and tfmr.fsos fields are used to select the required waveform. ? programmable low or high levels during data transfer are supported. ? programmable high levels before the start of data transfers or toggling are also supported. if a pulse waveform is selected, in reception, the receive frame sync length high part and the receive frame sync length fields in the rfmr register (rfmr.fslenhi and rfmr.fslen) define the length of the pulse, from 1 bit time up to 256 bit time. similarly, in transmission, the transmit frame sync length high part and the transmit frame sync length fields in the tfmr register (tfmr.fslenhi and tfmr.fslen) define the length of the pulse, from 1 bit up to 256 bit time. the periodicity of the rx_frame_sync and tx_frame_sync pulse outputs can be config- ured respectively through the receive period divider selection field in the rcmr register (rcmr.period) and the transmit period divider selection field in the tcmr register (tcmr.period). 24.7.5.1 frame sync data frame sync data transmits or receives a specific tag during the frame sync signal. during the frame sync signal, the receiver can sample the rx_data line and store the data in the receive sync holding register (rshr) and the transmitter can transfer the transmit sync holding register (tshr) in the shifter register. the data length to be sampled in reception during the frame sync signal shall be written to the rfmr.fslenhi and rfmr.fslen fields. the data length to be shifted out in transmission during the frame sync signal shall be written to the tfmr.fslenhi and tfmr.fslen fields. concerning the receive frame sync data operation, if the frame sync length is equal to or lower than the delay between the start event and the actual data reception, the data sampling operation is performed in the rshr through the receive shift register. the transmit frame sync operation is performed by the transmitter only if the frame sync data enable bit in tfmr register (tfmr.fsden) is wr itten to one. if the frame sync length is equal to or lower than the delay between the start event and the actual data transmission, the normal transmission has priority and the data contained in the tshr is transferred in the transmit regis- ter, then shifted out. 24.7.5.2 frame sync edge detection the frame sync edge detection is configured by writing to the frame sync edge detection bit in the rfmr/tfmr registers (rfmr.fsedge and tfmr.fsedge). this se ts the receive sync reception pulse length ((16 fslenhi ) fslen 1) receive clock periods ++ = transmission pulse length ((16 fslenhi ) fslen 1) transmit clock periods ++ =
518 32072d?04/2011 at32uc3a3/a4 and transmit sync bits in t he sr register (sr.rxsyn and sr.txsyn) on frame synchro edge detection (signals rx_fra me_sync/tx_frame_sync). 24.7.6 receive compare modes figure 24-12. receive compare modes 24.7.6.1 compare functions compare 0 can be one start event of the receiver. in this case, the receiver compares at each new sample the last {rfmr.fs lenhi, rfmr.fslen} bits received to the {rfmr.fslenhi, rfmr.fslen} lower bits of the data contained in the receive compare 0 register (rc0r). when this start event is selected, the user can program the receiver to start a new data transfer either by writing a new compare 0, or by receiving continuously until compare 1 occurs. this selection is done with the receive stop sele ction bit in the rcmr register (rcmr.stop). 24.7.7 data framing format the data framing format of both the transmitter and the receiver are programmable through the tfmr, tcmr, rfmr, and rcmr registers. in either case, the user can independently select: ? the event that starts the data transfer (rcmr.start and tcmr.start) ? the delay in number of bit periods between the start event and the first data bit (rcmr.sttdly and tcmr.sttdly) ? the length of the data (rfmr.datlen and tfmr.datlen) ? the number of data to be transferred for each start event (rfmr.datnb and tfmr.datlen) ? the length of synchronization transferred for each start event (rfmr.fslenhi, rfmr.fslen, tfmr.fsl enhi, and tfmr.fslen) ? the bit sense: most or lowest significant bit first (rfmr.msbf and tfmr.msbf) additionally, the transmitter can be used to tr ansfer synchronization and select the level driven on the tx_data pin while not in data transfer oper ation. this is done respectively by writing to the frame sync data enable and the data default value bits in the tfmr register (tfmr.fsden and tfmr.datdef). rx_data (input) rx_clock cmp0 cmp1 cmp2 cmp3 start {fslenhi,fslen} up to 256 bits (4 in this example) sttdly ignored datlen b2 b0 b1 table 24-3. data framing format registers transmitter receiver bi t/field length comment tcmr rcmr period up to 512 frame size tcmr rcmr start start selection tcmr rcmr sttdly up to 255 size of transmit start delay
519 32072d?04/2011 at32uc3a3/a4 figure 24-13. transmit and receive frame format in edge/pulse start modes note: example of input on falling edge of tx_frame_sync/rx_frame_sync. figure 24-14. transmit frame format in continuous mode note: sttdly is written to zero. in this example, t hr is loaded twice. fsden va lue has no effect on the transmission. syncdata cannot be output in continuous mode. tfmr rfmr datnb up to 16 number of words transmitted in frame tfmr rfmr datlen up to 32 size of word tfmr rfmr {fslenhi,fslen} up to 256 size of synchro data register tfmr rfmr msbf most significant bit first tfmr fsden enable send tshr tfmr datdef data default value ended table 24-3. data framing format registers transmitter receiver bi t/field length comment datnb datlen data data data data data data default default sync data sync data ignored from datdef start from datdef datlen to rhr to rhr from thr from thr from thr from thr from datdef from datdef ignored default default sync data to rshr from tshr fslen start tx_frame_sync / rx_frame_sync tx_data (if fsden = 1) tx_data (if fsden = 0) rx_data sttdly sync data period (1) start data data datlen from thr datlen tx_data start: 1. txempty set to one 2. write into the thr from thr default
520 32072d?04/2011 at32uc3a3/a4 figure 24-15. receive frame format in continuous mode note: sttdly is written to zero. 24.7.8 loop mode the receiver can be programmed to receive transmissions from the transmitter. this is done by writing a one to the loop mode bit in rfmr register (rfmr.loop). in this case, rx_data is connected to tx_data, rx_frame_sync is connected to tx_frame_sync and rx_clock is connected to tx_clock. 24.7.9 interrupt most bits in the sr register have a corresponding bit in interrupt management registers. the ssc can be programmed to generate an interrupt when it detects an event. the interrupt is controlled by writing to the interrupt enable register (ier) and interrupt disable register (idr). these registers enable and disable, respectively, the corresponding interrupt by setting and clearing the corresponding bit in the interrupt mask register (imr), which controls the genera- tion of interrupts by asserting the ssc interrupt line connected to the interrupt controller. figure 24-16. interrupt block diagram data data to rhr to rhr datlen datlen rx_data start = enable receiver im r ier id r clear set interrupt control ssc interrupt txrdy txempty txsync transmitter receiver rxrdy ovrun rxsync
521 32072d?04/2011 at32uc3a3/a4 24.8 ssc application examples the ssc can support several serial communica tion modes used in audio or high speed serial links. some standard applications are shown in t he following figures. all se rial link applications supported by the ssc are not listed here. figure 24-17. audio application block diagram figure 24-18. codec application block diagram clock sck word select ws data sd msb left channel lsb msb right channel data sd word select ws clock sck ssc tx_clock tx_frame_sync tx_data rx_data rx_frame_sync rx_clock i2s receiver ssc serial data clock (sclk) frame sync (fsync) serial data out serial data in serial data clock (sclk) frame sync (fsync) serial data out serial data in dstart dend first time slot codec tx_clock tx_frame_sync tx_data rx_data rx_frame_sync rx_clock
522 32072d?04/2011 at32uc3a3/a4 figure 24-19. time slot application block diagram codec first time slot codec second time slot data in data out fsync sclk serial data clock (sclk) frame sync (fsync) serial data out serial data in dstart first time slot second time slot dend ssc tx_clock tx_frame_sync tx_data rx_data rx_frame_sync rx_clock
523 32072d?04/2011 at32uc3a3/a4 24.9 user interface table 24-4. ssc register memory map offset register register name access reset 0x00 control register cr write-only 0x00000000 0x04 clock mode register cmr read/write 0x00000000 0x10 receive clock mode register rcmr read/write 0x00000000 0x14 receive frame mode register rfmr read/write 0x00000000 0x18 transmit clock mode register tcmr read/write 0x00000000 0x1c transmit frame mode register tfmr read/write 0x00000000 0x20 receive holding register rhr read-only 0x00000000 0x24 transmit holding register thr write-only 0x00000000 0x30 receive synchronization holding register rshr read-only 0x00000000 0x34 transmit synchronization holding register tshr read/write 0x00000000 0x38 receive compare 0 register rc0r read/write 0x00000000 0x3c receive compare 1 register rc1r read/write 0x00000000 0x40 status register sr read-only 0x000000cc 0x44 interrupt enable register ier write-only 0x00000000 0x48 interrupt disable register idr write-only 0x00000000 0x4c interrupt mask register imr read-only 0x00000000
524 32072d?04/2011 at32uc3a3/a4 24.9.1 control register name: cr access type: write-only offset: 0x00 reset value: 0x00000000 ? swrst: software reset 1: writing a one to this bit will perform a software rese t. this software reset has priority on any other bit in cr. 0: writing a zero to this bit has no effect. ? txdis: transmit disable 1: writing a one to this bit will disable the transmission. if a character is currently being tr ansmitted, the disable occurs a t the end of the current character transmission. 0: writing a zero to this bit has no effect. ? txen: transmit enable 1: writing a one to this bit will enable the transmission if the txdis bit is not written to one. 0: writing a zero to this bit has no effect. ? rxdis: receive disable 1: writing a one to this bit will disable the reception. if a c haracter is currently being received, the disable occurs at the end of current character reception. 0: writing a zero to this bit has no effect. ? rxen: receive enable 1: writing a one to this bit will enables the rec eption if the rxdis bit is not written to one. 0: writing a zero to this bit has no effect. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 swrst-----txdistxen 76543210 ------rxdisrxen
525 32072d?04/2011 at32uc3a3/a4 24.9.2 clock mode register name: cmr access type: read/write offset: 0x04 reset value: 0x00000000 ? div[11:0]: clock divider the divided clock equals the clk_ssc divided by two times div. the maximum bit rate is clk_ssc/2. the minimum bit rate is clk_ssc/(2 x 4095) = clk_ssc/8190. the clock divider is not active when div equals zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - div[11:8] 76543210 div[7:0] divided clock clk_ssc ( ? div 2) =
526 32072d?04/2011 at32uc3a3/a4 24.9.3 receive clock mode register name: rcmr access type: read/write offset: 0x10 reset value: 0x00000000 ? period: receive period divider selection this field selects the divider to apply to the selected receive clock in order to generate a periodic frame sync signal. if equal to zero, no signal is generated. if not equal to zero, a signal is generated each 2 x (period+1) receive clock periods. ? sttdly: receive start delay if sttdly is not zero, a delay of sttdly clock cycles is inse rted between the start event and t he actual start of reception. when the receiver is programmed to start synchronously with the transmitter, the delay is also applied. note: it is very important that sttdly be written carefully. if st tdly must be written, it should be done in relation to receiv e sync data reception. ? stop: receive stop selection 1: after starting a receive with a compare 0, the receiver o perates in a continuous mode until a compare 1 is detected. 0: after completion of a data transfer when starting with a comp are 0, the receiver stops the data transfer and waits for a new compare 0. 31 30 29 28 27 26 25 24 period 23 22 21 20 19 18 17 16 sttdly 15 14 13 12 11 10 9 8 ---stop start 76543210 ckg cki cko cks
527 32072d?04/2011 at32uc3a3/a4 ? start: receive start selection ? ckg: receive clock gating selection ? cki: receive clock inversion cki affects only the receive clock and not the output clock signal. 1: the data inputs (data and frame sync signals) are sampled on receive clock rising edge. the frame sync signal output is shifted out on receive clock falling edge. 0: the data inputs (data and frame sync signals) are sampled on receive clock falling edge. the frame sync signal output is shifted out on receive clock rising edge. ? cko: receive clock output mode selection ? cks: receive clock selection start receive start 0 continuous, as soon as the receiver is enabled, and immediately after the end of transfer of the previous data. 1 transmit start 2 detection of a low level on rx_frame_sync signal 3 detection of a high level on rx_frame_sync signal 4 detection of a falling edge on rx_frame_sync signal 5 detection of a rising edge on rx_frame_sync signal 6 detection of any level change on rx_frame_sync signal 7 detection of any edge on rx_frame_sync signal 8 compare 0 others reserved ckg receive clock gating 0 none, continuous clock 1 receive clock enabled only if rx_frame_sync is low 2 receive clock enabled only if rx_frame_sync is high 3 reserved cko receive clock output mode rx_clock pin 0 none input-only 1 continuous receive clock output 2 receive clock only during data transfers output others reserved cks selected receive clock 0 divided clock 1 tx_clock clock signal 2 rx_clock pin 3 reserved
528 32072d?04/2011 at32uc3a3/a4 24.9.4 receive frame mode register name: rfmr access type: read/write offset: 0x14 reset value: 0x00000000 ? fslenhi: receive frame sync length high part the four msb of the fslen field. ? fsedge: receive frame sync edge detection determines which edge on frame sync will generate the sr.rxsyn interrupt. ? fsos: receive frame sync output selection ? fslen: receive frame sync length this field defines the length of the receive frame sync signal and the number of bits sampled and stored in the rshr register. when this mode is selected by the rcmr.start field, it also dete rmines the length of the sampled data to be compared to the compare 0 or compare 1 register. note: the four most significant bits for th is field are located in the fslenhi field. the pulse length is equal to ({fslenhi,fslen} + 1) receive clock periods. thus, if {fslenhi,fslen} is zero, the receive frame sync signal is generated during one receive clock period. 31 30 29 28 27 26 25 24 fslenhi - - - fsedge 23 22 21 20 19 18 17 16 - fsos fslen 15 14 13 12 11 10 9 8 ---- datnb 76543210 msbf - loop datlen fsedge frame sync edge detection 0 positive edge detection 1 negative edge detection fsos selected receive frame sy nc signal rx_f rame_sync pin 0 none input-only 1 negative pulse output 2 positive pulse output 3 driven low during data transfer output 4 driven high during data transfer output 5 toggling at each start of data transfer output others reserved undefined
529 32072d?04/2011 at32uc3a3/a4 ? datnb: data number per frame this field defines the number of data words to be received after each transfer start, which is equal to (datnb + 1). ? msbf: most significant bit first 1: the most significant bit of the data re gister is sampled first in the bit stream. 0: the lowest significant bit of the data r egister is sampled first in the bit stream. ? loop: loop mode 1: rx_data is driven by tx_data, rx_frame_sync is dr iven by tx_frame_sync and tx_clock drives rx_clock. 0: normal operating mode. ? datlen: data length the bit stream contains (datlen + 1) data bits. this field also defines the transfer size performed by the peripheral dma controller assigned to the receiver. datlen transfer size 0 forbidden value 1-7 data transfer are in bytes 8-15 data transfer are in halfwords others data transfer are in words
530 32072d?04/2011 at32uc3a3/a4 24.9.5 transmit clock mode register name: tcmr access type: read/write offset: 0x18 reset value: 0x00000000 ? period: transmit period divider selection this field selects the divider to apply to the selected transmit clock in order to generate a periodic frame sync signal. if equal to zero, no signal is generated. if not equal to zero, a signal is generated each 2 x (period+1) transmit clock periods. ? sttdly: transmit start delay if sttdly is not zero, a delay of sttdly clock cycles is inse rted between the start event and t he actual start of transmission. when the transmitter is programmed to start synchronously with the receiver, the delay is also applied. note: sttdly must be written carefully, in relation to transmit sync data transmission. ? start: transmit start selection 31 30 29 28 27 26 25 24 period 23 22 21 20 19 18 17 16 sttdly 15 14 13 12 11 10 9 8 - - - - start 76543210 ckg cki cko cks start transmit start 0 continuous, as soon as a word is written to the thr register (if transmit is enabled), and immediately after the end of tr ansfer of the previous data. 1 receive start 2 detection of a low level on tx_frame_sync signal 3 detection of a high level on tx_frame_sync signal 4 detection of a falling edge on tx_frame_sync signal 5 detection of a rising edge on tx_frame_sync signal 6 detection of any level change on tx_frame_sync signal 7 detection of any edge on tx_frame_sync signal others reserved
531 32072d?04/2011 at32uc3a3/a4 ? ckg: transmit clock gating selection ? cki: transmit clock inversion cki affects only the transmit clock and not the output clock signal. 1: the data outputs (data and frame sync si gnals) are shifted out on transmit clock rising edge. the frame sync signal input is sampled on transmit clock falling edge. 0: the data outputs (data and fr ame sync signals) are shifted out on transmit clock falling edge. the frame sync signal input i s sampled on transmit clock rising edge. ? cko: transmit clock output mode selection ? cks: transmit clock selection ckg transmit clock gating 0 none, continuous clock 1 transmit clock enabled only if tx_frame_sync is low 2 transmit clock enabled only if tx_frame_sync is high 3 reserved cko transmit clock output mode tx_clock pin 0 none input-only 1 continuous transmit clock output 2 transmit clock only during data transfers output others reserved cks selected transmit clock 0 divided clock 1 rx_clock clock signal 2 tx_clock pin 3 reserved
532 32072d?04/2011 at32uc3a3/a4 24.9.6 transmit frame mode register name: tfmr access type: read/write offset: 0x1c reset value: 0x00000000 ? fslenhi: transmit frame sync length high part the four msb of the fslen field. ? fsedge: transmit frame sync edge detection determines which edge on frame sync will generate the sr.txsyn interrupt. ? fsden: transmit frame sync data enable 1: tshr value is shifted out during the tran smission of the transmit frame sync signal. 0: the tx_data line is driven with the default value during the transmit frame sync signal. ? fsos: transmit frame sync output selection ? fslen: transmit frame sync length this field defines the length of the transmit frame sync signal and the number of bi ts shifted out from the tshr register if tfmr.fsden is equal to one. note: the four most significant bits for th is field are located in the fslenhi field. 31 30 29 28 27 26 25 24 fslenhi - - - fsedge 23 22 21 20 19 18 17 16 fsden fsos fslen 15 14 13 12 11 10 9 8 ---- datnb 76543210 m s b f - dat d e f dat l e n fsedge frame sync edge detection 0 positive edge detection 1 negative edge detection fsos selected transmit frame sync signal tx_frame_sync pin 0 none input-only 1 negative pulse output 2 positive pulse output 3 driven low during data transfer output 4 driven high during data transfer output 5 toggling at each start of data transfer output others reserved undefined
533 32072d?04/2011 at32uc3a3/a4 the pulse length is equal to ({fslenhi,fslen} + 1) transmit cl ock periods, i.e., the pulse length can range from 1 to 256 transmit clock periods. if {fslenhi,fslen } is zero, the transmit frame sync signal is generated during one transmit clock period. ? datnb: data number per frame this field defines the number of data words to be transferre d after each transfer start, which is equal to (datnb + 1). ? msbf: most significant bit first 1: the most significant bit of the data regi ster is shifted out first in the bit stream. 0: the lowest significant bit of the data register is shifted out first in the bit stream. ? datdef: data default value this bit defines the level driven on the tx_data pin while out of transmission. note that if the pin is defined as multi-drive by the i/o c ontroller, the pin is enabled only if the tx_data output is one. 1: the level driven on the tx_data pin while out of transmission is one. 0: the level driven on the tx_data pin while out of transmission is zero. ? datlen: data length the bit stream contains (datlen + 1) data bits. this field also defines the transfer size performed by t he peripheral dma controller assigned to the transmitter. datlen transfer size 0 forbidden value (1-bit data length is not supported) 1-7 data transfer are in bytes 8-15 data transfer are in halfwords others data transfer are in words
534 32072d?04/2011 at32uc3a3/a4 24.9.7 receive holding register name: rhr access type: read-only offset: 0x20 reset value: 0x00000000 ? rdat: receive data right aligned regardless of the number of data bits defined by the rfmr.datlen field. 31 30 29 28 27 26 25 24 rdat[31:24] 23 22 21 20 19 18 17 16 rdat[23:16] 15 14 13 12 11 10 9 8 rdat[15:8] 76543210 rdat[7:0]
535 32072d?04/2011 at32uc3a3/a4 24.9.8 transmit holding register name: thr access type: write-only offset: 0x24 reset value: 0x00000000 ? tdat: transmit data right aligned regardless of the number of data bits defined by the tfmr.datlen field. 31 30 29 28 27 26 25 24 tdat[31:24] 23 22 21 20 19 18 17 16 tdat[23:16] 15 14 13 12 11 10 9 8 tdat[15:8] 76543210 tdat[7:0]
536 32072d?04/2011 at32uc3a3/a4 24.9.9 receive synchronization holding register name: rshr access type: read-only offset: 0x30 reset value: 0x00000000 ? rsdat: receive synchronization data 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 rsdat[15:8] 76543210 rsdat[7:0]
537 32072d?04/2011 at32uc3a3/a4 24.9.10 transmit synchronization holding register name: tshr access type: read/write offset: 0x34 reset value: 0x00000000 ? tsdat: transmit synchronization data 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 tsdat[15:8] 76543210 tsdat[7:0]
538 32072d?04/2011 at32uc3a3/a4 24.9.11 receive compare 0 register name: rc0r access type: read/write offset: 0x38 reset value: 0x00000000 ? cp0: receive compare data 0 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 cp0[15:8] 76543210 cp0[7:0]
539 32072d?04/2011 at32uc3a3/a4 24.9.12 receive compare 1 register name: rc1r access type: read/write offset: 0x3c reset value: 0x00000000 ? cp1: receive compare data 1 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 cp1[[15:8] 76543210 cp1[7:0]
540 32072d?04/2011 at32uc3a3/a4 24.9.13 status register name: sr access type: read-only offset: 0x40 reset value: 0x000000cc ? rxen: receive enable this bit is set when the cr.rxen bit is written to one. this bit is cleared when no data are being proce ssed and the cr.rxdis bit has been written to one. ? txen: transmit enable this bit is set when the cr.txen bit is written to one. this bit is cleared when no data are being proce ssed and the cr.txdis bit has been written to one. ? rxsyn: receive sync this bit is set when a receive sync has occurred. this bit is cleared when the sr register is read. ? txsyn: transmit sync this bit is set when a transmit sync has occurred. this bit is cleared when the sr register is read. ? cp1: compare 1 this bit is set when compare 1 has occurred. this bit is cleared when the sr register is read. ? cp0: compare 0 this bit is set when compare 0 has occurred. this bit is cleared when the sr register is read. ? ovrun: receive overrun this bit is set when data has been loaded in the rhr register while previous data has not yet been read. this bit is cleared when the sr register is read. ? rxrdy: receive ready this bit is set when data has been received and loaded in the rhr register. this bit is cleared when the rhr register is empty. ? txempty: transmit empty this bit is set when the last data written in the thr register has been loaded in the tsr register and last data loaded in the tsr register has been transmitted. this bit is cleared when data remains in the thr regist er or is currently transmitted from the tsr register. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - - - rxen txen 15 14 13 12 11 10 9 8 - - - - rxsyn txsyn cp1 cp0 76543210 - - ovrun rxrdy - - txempty txrdy
541 32072d?04/2011 at32uc3a3/a4 ? txrdy: transmit ready this bit is set when the thr register is empty. this bit is cleared when data has been loaded in the thr re gister and is waiting to be loaded in the tsr register.
542 32072d?04/2011 at32uc3a3/a4 24.9.14 interrupt enable register name: ier access type: write-only offset: 0x44 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will set the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - rxsyn txsyn cp1 cp0 76543210 ? ? ovrun rxrdy ? ? txempty txrdy
543 32072d?04/2011 at32uc3a3/a4 24.9.15 interrupt disable register name: idr access type: write-only offset: 0x48 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - rxsyn txsyn cp1 cp0 76543210 ? ? ovrun rxrdy ? ? txempty txrdy
544 32072d?04/2011 at32uc3a3/a4 24.9.16 interrupt mask register name: imr access type: read-only offset: 0x4c reset value: 0x00000000 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. a bit in this register is cleared when the corresponding bit in idr is written to one. a bit in this register is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - - rxsyn txsyn cp1 cp0 76543210 ? ? ovrun rxrdy ? ? txempty txrdy
545 32072d?04/2011 at32uc3a3/a4 25. universal synchronous asynchrono us receiver transmitter (usart) rev: 4.2.0.5 25.1 features ? configurable baud rate generator ? 5- to 9-bit full-duplex synchronous or asynchronous ser ial communication ? 1, 1.5, or 2 stop bits in asynchrono us mode, and 1 or 2 in synchronous mode ? parity generation and error detection ? framing- and overrun error detection ? msb- or lsb-first ? optional break generation and detection ? receiver frequency over-sampling by 8 or 16 times ? optional rts-cts hardware handshaking ? optional dtr-dsr-dcd-ri modem signal management ? receiver time-out and transmitter timeguard ? optional multidrop mode with address generation and detection ? rs485 with line driver control ? iso7816, t=0 and t=1 protocols for interfacing with smart cards ? nack handling ? error counter with configurable repetition and iteration limits ? irda modulation and demodulation ? communication at up to 115.2kbit/s ? spi mode ? master or slave ? configurable serial cl ock phase and polarity ? clk spi serial clock frequenc y up to a quarter of the clk_usart internal clock frequency ? lin mode ? compliant with lin 1.3 and lin 2.0 sp ecifications ? master or slave ? processing of frames with up to 256 data bytes ? configurable response data lengt, optional ly defined automatically by the identifier ? self synchronization in slave node configuration ? automatic processing and verification of the ?sync break? and ?sync field? ? the ?sync break? is detected even if it is partially superimposed with a data byte ? optional, automatic iden tifier parity management ? optional, automatic checksum management ? supports both ?classic? an d ?enhanced? checksum types ? full lin error checking and reporting ? frame slot mode: the master allocates slots to scheduled frames automatically. ? wakeup signal generation ? test modes ? automatic echo, remo te- and local loopback ? supports two peripheral dma controller channels ? buffer transfers without processor intervention 25.2 overview the universal synchronous asynchronous rece iver transceiver (usart) provides one full duplex universal synchronous asynchronous serial link. data frame format is widely programma- ble (data length, parity, number of stop bits) to support a maximum of standards. the receiver
546 32072d?04/2011 at32uc3a3/a4 implements parity error, framing error and overrun error detection. the receiver time-out enables handling variable-length frames and the transmitt er timeguard facilitates communications with slow remote devices. multidrop communications are also supported through address bit han- dling in reception and transmission. the usart features three test modes: remote loopback, local loopback and automatic echo. the usart supports specific operating modes providing interfaces on rs485, lin and spi buses, with iso7816 t = 0 or t = 1 smart card slots, infrared transceivers and connection to modem ports. the hardware handshaking feature enables an out-of-band flow control by auto- matic management of the pins rts and cts. the usart supports the connection to the peripheral dma controller, which enables data transfers to the transmitter and from the receiver. the peripheral dma controller provides chained buffer management without any intervention of the processor. 25.3 block diagram figure 25-1. usart block diagram peripheral dma controller channel channel intc power manager div receiver transmitter modem signals control user interface i/o controller rxd rts txd cts dtr dsr dcd ri clk baudrate generator usart interrupt clk_usart clk_usart/div usart peripheral bus
547 32072d?04/2011 at32uc3a3/a4 25.4 i/o lines description table 25-1. spi operating mode pin usart spi slave spi master rxd rxd mosi miso txd txd miso mosi rts rts ? cs cts cts cs ? table 25-2. i/o lines description name description type active level clk serial clock i/o txd transmit serial data or master out slave in (mosi) in spi master mode or master in slave out (miso) in spi slave mode output rxd receive serial data or master in slave out (miso) in spi master mode or master out slave in (mosi) in spi slave mode input ri ring indicator input low dsr data set ready input low dcd data carrier detect input low dtr data terminal ready output low cts clear to send or slave select (nss) in spi slave mode input low rts request to send or slave select (nss) in spi master mode output low
548 32072d?04/2011 at32uc3a3/a4 25.5 product dependencies 25.5.1 i/o lines the pins used for interfacing the usart may be multiplexed with the i/o controller lines. the programmer must first program the i/o controller to assign the desired usart pins to their peripheral function. if i/o lines of the usart are not used by the application, they can be used for other purposes by the i/o controller. to prevent the txd line from falling when the usart is di sabled, the use of an internal pull up is mandatory. if the hardware handshaking feature or modem mode is used, the internal pull up on txd must also be enabled. all the pins of the modems may or may not be implemented on the usart. on usarts not equipped with the corresponding pins, the associat ed control bits and statuses have no effect on the behavior of the usart. 25.5.2 clocks the clock for the usart bus interface (clk_usart) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to dis- able the usart before disabling the clock, to avoid freezing the usart in an undefined state. 25.5.3 interrupts the usart interrupt request line is connected to the interrupt controller. using the usart interrupt requires the interrupt controller to be programmed first.
549 32072d?04/2011 at32uc3a3/a4 25.6 functional description the usart is capable of managing several ty pes of serial synchronous or asynchronous communications. it supports the following communication modes: ? 5- to 9-bit full-duplex asynchronous serial communication ? msb- or lsb-first ? 1, 1.5 or 2 stop bits ? parity even, odd, marked, space or none ? by 8 or by 16 over-sampling receiver frequency ? optional hardware handshaking ? optional modem signals management ? optional break management ? optional multidrop serial communication ? high-speed 5- to 9-bit full-duplex synchronous serial communication ? msb- or lsb-first ? 1 or 2 stop bits ? parity even, odd, marked, space or none ? by 8 or by 16 over-sampling frequency ? optional hardware handshaking ? optional modem signals management ? optional break management ? optional multidrop serial communication ? rs485 with driver control signal ? iso7816, t0 or t1 protocols for interfacing with smart cards ? nack handling, error counter with repetition and iteration limit ? infrared irda modulation and demodulation ? spi mode ?master or slave ? serial clock programmable phase and polarity ? spi serial clock (clk) frequency up to internal clock frequency clk_usart/4 ? lin mode ? compliant with lin 1.3 a nd lin 2.0 specifications ?master or slave ? processing of frames with up to 256 data bytes ? response data length can be configurable or defined automatically by the identifier ? self synchronization in slave node configuration ? automatic processing and verification of the ?synch break? and the ?synch field? ? the ?synch break? is detected even if it is partially superimposed with a data byte ? automatic identifier parity calculation/sending and verification ? parity sending and verification can be disabled ? automatic checksum calculation/sending and verification ? checksum sending and verification can be disabled ? support both ?classic? and ?enhanced? checksum types
550 32072d?04/2011 at32uc3a3/a4 ? full lin error checking and reporting ? frame slot mode: the master allocates slots to the scheduled frames automatically. ? generation of the wakeup signal ? test modes ? remote loopback, local loopback, automatic echo 25.6.1 baud rate generator the baud rate generator provides the bit period clock named the baud rate clock to both the receiver and the transmitter. the baud rate generator clock source can be selected by setting the usclks field in the mode register (mr) between: ? clk_usart ? a division of clk_usart, the divider being product dependent, but generally set to 8 ? the external clock, available on the clk pin the baud rate generator is based upon a 16-bit divider, which is programmed with the cd field of the baud rate generator register (brgr). if cd is programmed at 0, the baud rate gener- ator does not generate any clock. if cd is programmed at 1, the divider is bypassed and becomes inactive. if the external clk clock is selected, the duration of the low and high levels of the signal pro- vided on the clk pin must be longer than a clk_usart period. the frequency of the signal provided on clk must be at least 4.5 times lower than clk_usart. figure 25-2. baud rate generator 25.6.1.1 baud rate in asynchronous mode if the usart is programmed to operate in as ynchronous mode, the selected clock is first divided by cd, which is field programmed in the baud rate generator register (brgr). the resulting clock is provided to the receiver as a sampling clock and then divided by 16 or 8, depending on the programming of the over bit in mr. if over is set to 1, the receiver sampling is 8 times higher than the baud rate clock. if over is cleared, the sampling is performed at 16 times the baud rate clock. 16-bit counter cd usclks cd clk_usart clk_usart/div reserved clk sync sync usclks= 3 fidi over sampling divider baudrate clock sampling clock 1 0 0 clk 0 1 2 3 >1 1 1 0 0
551 32072d?04/2011 at32uc3a3/a4 the following formula performs the calculation of the baud rate. this gives a maximum baud rate of clk_usar t divided by 8, assuming that clk_usart is the highest possible clock and that over is programmed at 1. 25.6.1.2 baud rate calculation example table 25-3 shows calculations of cd to obtain a baud rate at 38400 bauds for different source clock frequencies. this table also shows the actual resulting baud rate and the error. the baud rate is calculated with the following formula: the baud rate error is calculated with the following formula. it is not recommended to work with an error higher than 5%. baudrate selectedclock 82 over ? () cd () -------------------------------------------- = table 25-3. baud rate example (over = 0) source clock expected baud rate calculation result cd actual baud rate error mhz bit/s bit/s 3 686 400 38 400 6.00 6 38 400.00 0.00% 4 915 200 38 400 8.00 8 38 400.00 0.00% 5 000 000 38 400 8.14 8 39 062.50 1.70% 7 372 800 38 400 12.00 12 38 400.00 0.00% 8 000 000 38 400 13.02 13 38 461.54 0.16% 12 000 000 38 400 19.53 20 37 500.00 2.40% 12 288 000 38 400 20.00 20 38 400.00 0.00% 14 318 180 38 400 23.30 23 38 908.10 1.31% 14 745 600 38 400 24.00 24 38 400.00 0.00% 18 432 000 38 400 30.00 30 38 400.00 0.00% 24 000 000 38 400 39.06 39 38 461.54 0.16% 24 576 000 38 400 40.00 40 38 400.00 0.00% 25 000 000 38 400 40.69 40 38 109.76 0.76% 32 000 000 38 400 52.08 52 38 461.54 0.16% 32 768 000 38 400 53.33 53 38 641.51 0.63% 33 000 000 38 400 53.71 54 38 194.44 0.54% 40 000 000 38 400 65.10 65 38 461.54 0.16% 50 000 000 38 400 81.38 81 38 580.25 0.47% 60 000 000 38 400 97.66 98 38 265.31 0.35% baudrate clkusart () cd 16 () ? =
552 32072d?04/2011 at32uc3a3/a4 25.6.1.3 fractional baud rate in asynchronous mode the baud rate generator previously defined is su bject to the following limitation: the output fre- quency changes by only integer multiples of the reference frequency. an approach to this problem is to integrate a fractional n clock generator that has a high resolution. the generator architecture is modified to obtain baud rate c hanges by a fraction of the reference source clock. this fractional part is programmed with the fp field in the baud rate generator register (brgr). if fp is not 0, the fractional part is acti vated. the resolution is one eighth of the clock divider. this feature is only available when using usart normal mode. the fractional baud rate is calculated using the following formula: the modified architecture is presented below: figure 25-3. fractional baud rate generator 25.6.1.4 baud rate in synchronous mode or spi mode if the usart is programmed to operate in synchronous mode, the selected clock is simply divided by the field cd in brgr. error 1 expectedbaudrate actualbaudrate -------------------------------------------------- - ?? ?? ? = baudrate selectedclock 82 over ? () cd fp 8 ------- + ?? ?? ?? ?? ---------------------------------------------------------------- - = usclks cd modulus control fp fp cd glitch-free logic 16-bit counter over fidi sync sampling divider clk_usart clk_usart/div reserved clk clk baudrate clock sampling clock sync usclks = 3 >1 1 2 3 0 0 1 0 1 1 0 0 baudrate selectedclock cd ------------------------------------- - =
553 32072d?04/2011 at32uc3a3/a4 in synchronous mode, if the external clock is selected (usclks = 3), the clock is provided directly by the signal on the usart clk pin. no division is active. the value written in brgr has no effect. the external clock frequency must be at least 4.5 times lower than the system clock. when either the external clock clk or the inte rnal clock divided (clk_usart/div) is selected, the value programmed in cd must be even if the user has to ensure a 50:50 mark/space ratio on the clk pin. if the internal clock clk_usart is selected, the baud rate generator ensures a 50:50 duty cycle on the clk pin, even if the value programmed in cd is odd. 25.6.1.5 baud rate in iso 7816 mode the iso7816 specification defines the bit rate with the following formula: where: ? b is the bit rate ? di is the bit-rate adjustment factor ? fi is the clock frequency division factor ? f is the iso7816 clock frequency (hz) di is a binary value encoded on a 4-bit field, named di, as represented in table 25-4 . fi is a binary value encoded on a 4-bi t field, named fi, as represented in table 25-5 . table 25-6 shows the resulting fi/di ratio, which is the ratio between the iso7816 clock and the baud rate clock. if the usart is configured in iso7816 mode, th e clock selected by the usclks field in the mode register (mr) is first divided by the valu e programmed in the field cd in the baud rate b di fi ----- - f = table 25-4. binary and decimal values for di di field 0001 0010 0011 0100 0101 0110 1000 1001 di (decimal)1 2 4 8 163212 20 table 25-5. binary and decimal values for fi fi field 0000 0001 0010 0011 0100 0101 0110 1001 1010 1011 1100 1101 fi (decimal 372 372 558 744 1116 1488 1860 512 768 1024 1536 2048 table 25-6. possible values for the fi/di ratio fi/di 372 558 774 1116 1488 1806 512 768 1024 1536 2048 1 372 558 744 1116 1488 1860 512 768 1024 1536 2048 2 186 279 372 558 744 930 256 384 512 768 1024 4 93 139.5 186 279 372 465 128 192 256 384 512 8 46.5 69.75 93 139.5 186 232.5 64 96 128 192 256 16 23.25 34.87 46.5 69.75 93 116.2 32 48 64 96 128 32 11.62 17.43 23.25 34.87 46.5 58.13 16 24 32 48 64 12 31 46.5 62 93 124 155 42.66 64 85.33 128 170.6 20 18.6 27.9 37.2 55.8 74.4 93 25.6 38.4 51.2 76.8 102.4
554 32072d?04/2011 at32uc3a3/a4 generator register (brgr). the resulting clock can be provided to the clk pin to feed the smart card clock inputs. this means that the clko bit can be set in mr. this clock is then divided by the value progra mmed in the fi_di_ratio field in the fi_di_ratio register (fidi). this is performed by the sampling divider, which performs a division by up to 2047 in iso7816 mode. the non-integer values of the fi/di ratio are not supported and the user must program the fi_di_ratio field to a value as close as possible to the expected value. the fi_di_ratio field resets to the value 0x174 (372 in decimal) and is the most common divider between the iso7816 clock and the bit rate (fi = 372, di = 1). figure 25-4 shows the relation between the elementary time unit, corresponding to a bit time, and the iso 7816 clock. figure 25-4. elementary time unit (etu) 25.6.2 receiver and transmitter control after reset, the receiver is disabled. the user must enable the receiver by setting the rxen bit in the control register (cr). however, the receiver registers can be programmed before the receiver clock is enabled. after reset, the transmitter is disabled. the user must enable it by setting the txen bit in the control register (cr). however, the transmitter registers can be programmed before being enabled. the receiver and the transmitter can be enabled together or independently. at any time, the software can perform a reset on the receiver or the transmitter of the usart by setting the corresponding bit, rstrx and rsttx re spectively, in the control register (cr). the software resets clear the status flag and rese t internal state machines but the user interface configuration registers hold the value configured prior to software reset. regardless of what the receiver or the transmitter is performing, the communication is immediately stopped. the user can also independently disable the receiv er or the transmitter by setting rxdis and txdis respectively in cr. if the receiver is disabled during a character reception, the usart waits until the end of reception of the current character, then the reception is stopped. if the transmitter is disabled while it is operating, the usart waits the end of transmission of both the current character and character being stored in the transmit holding register (thr). if a time- guard is programmed, it is handled normally. 1 etu fi_di_ratio iso7816 clock cycles iso7816 clock on clk iso7816 i/o line on txd
555 32072d?04/2011 at32uc3a3/a4 25.6.3 synchronous and asynchronous modes 25.6.3.1 transmitter operations the transmitter performs the same in both synchronous and asynchronous operating modes (sync = 0 or sync = 1). one start bit, up to 9 da ta bits, one optional parity bit and up to two stop bits are successively shifted out on the txd pin at each falling edge of the programmed serial clock. the number of data bits is selected by the chrl field and the mode 9 bit in the mode register (mr). nine bits are selected by setting the mode 9 bit regardless of the chrl field. the parity bit is set according to the par field in mr. the even, odd, space, marked or none parity bit can be configured. the msbf field in mr configures wh ich data bit is sent first. if written at 1, the most significant bit is sent first. at 0, the less signi ficant bit is sent first. the number of stop bits is selected by the nbstop field in mr. the 1.5 stop bit is supported in asynchronous mode only. figure 25-5. character transmit the characters are sent by writing in the tr ansmit holding register (thr). the transmitter reports two status bits in the channel status register (csr): txrdy (transmitter ready), which indicates that thr is empt y and txempty, which indicates that all the characters written in thr have been processed. when the current character processing is completed, the last character written in thr is transferred into the shift register of the transmitter and thr becomes empty, thus txrdy rises. both txrdy and txempty bits are low when the transmitter is disabled. writing a character in thr while txrdy is low has no effect and the written character is lost. figure 25-6. transmitter status d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit example: 8-bit, parity enabled one stop baud rate clock d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit baud rate clock start bit write thr d0 d1 d2 d3 d4 d5 d6 d7 parity bit stop bit txrdy txempty
556 32072d?04/2011 at32uc3a3/a4 25.6.3.2 manchester encoder when the manchester encoder is in use, c haracters transmitted through the usart are encoded based on biphase manchester ii format. to enable this mode, set the man field in the mr register to 1. depending on polarity configurat ion, a logic level (zero or one), is transmitted as a coded signal one-to-zero or zero-to-one. thus, a transition always occurs at the midpoint of each bit time. it consumes more bandwidth than the original nrz signal (2x) but the receiver has more error control since the expected input must show a change at the center of a bit cell. an example of manchester encoded sequence is: th e byte 0xb1 or 10110001 encodes to 10 01 10 10 01 01 01 10, assuming the default polarity of the encoder. figure 25-7 illustrates this coding scheme. figure 25-7. nrz to manchester encoding the manchester encoded character can also be enc apsulated by adding both a configurable preamble and a start frame delimiter pattern. depending on the configuration, the preamble is a training sequence, composed of a pre-defined pattern with a programmable length from 1 to 15 bit times. if the preamble length is set to 0, the preamble waveform is not generated prior to any character. the preamble pattern is chosen among the following sequences: all_one, all_zero, one_zero or zero_one, writing the field tx_pp in the man register, the field tx_pl is used to configure the preamble length. figure 25-8 illustrates and defines the valid patterns. to improve flexibility, the encodi ng scheme can be configured using the tx_mpol field in the man register. if the tx_mpol field is set to zero (default), a logic zero is encoded with a zero-to-one transition and a logic one is encoded with a one-to-zero transition. if the tx_mpol field is set to one, a logic one is encoded with a one-to-zero transition and a logic zero is encoded with a zero-to-one transition. nrz encoded data manchester encoded data 10110001 txd
557 32072d?04/2011 at32uc3a3/a4 figure 25-8. preamble patterns, default polarity assumed a start frame delimiter is to be configured using the onebit field in the mr register. it consists of a user-defined pattern that indicates the beginning of a valid data. figure 25-9 illustrates these patterns. if the start frame delimiter, also known as start bit, is one bit, (onebit at 1), a logic zero is manchester encoded and indicates that a new character is being sent serially on the line. if the start frame delimiter is a synchronization pattern also referred to as sync (onebit at 0), a sequence of 3 bit times is sent serially on the line to indicate the start of a new character. the sync waveform is in itself an invalid manchester waveform as the transition occurs at the middle of the second bit time. two distinct sync patterns are used: the command sync and the data sync. the command sync has a logic one level for one and a half bit times, then a transition to logic zero for the second one and a half bit times. if the modsync field in the mr register is set to 1, the next character is a command. if it is set to 0, the next character is a data. when direct memory access is used, the modsync field can be immediately updated with a modified character located in memory. to enable this mode, var_sync field in mr register must be set to 1. in this case, the modsync field in mr is bypassed and the sync configuration is held in the txsynh in the thr register. the usart character format is modified and includes sync information. manchester encoded data txd sfd data 8 bit width "all_one" preamble manchester encoded data txd sfd data 8 bit width "all_zero" preamble manchester encoded data txd sfd data 8 bit width "zero_one" preamble manchester encoded data txd sfd data 8 bit width "one_zero" preamble
558 32072d?04/2011 at32uc3a3/a4 figure 25-9. start frame delimiter drift compensation drift compensation is available only in 16x oversampling mode. an ha rdware recovery system allows a larger clock drift. to enable the hardwa re system, the bit in th e man register must be set. if the rxd edge is one 16x clock cycle from the expected edge, this is considered as nor- mal jitter and no corrective actions is taken. if the rxd event is between 4 and 2 clock cycles before the expected edge, then the current period is shortened by one clock cycle. if the rxd event is between 2 and 3 clock cycles after the expected edge, then the current period is length- ened by one clock cycle. these intervals are considered to be drift and so corrective actions are automatically taken. figure 25-10. bit resynchronization 25.6.3.3 asynchronous receiver if the usart is programmed in asynchronous operating mode (sync = 0), the receiver over- samples the rxd input line. the oversampling is either 16 or 8 times the baud rate clock, depending on the over bit in the mode register (mr). manchester encoded data txd sfd data one bit start frame delimiter preamble length is set to 0 manchester encoded data txd sfd data command sync start frame delimiter manchester encoded data txd sfd data data sync start frame delimiter rxd oversampling 16x clock sampling point expected edge tolerance synchro. jump sync jump synchro. error synchro. error
559 32072d?04/2011 at32uc3a3/a4 the receiver samples the rxd line. if the line is sampled during one half of a bit time at 0, a start bit is detected and data, parity and stop bits are successively sampled on the bit rate clock. if the oversampling is 16, (over at 0), a start is detected at the eighth sample at 0. then, data bits, parity bit and stop bit are sampled on each 16 sampling clock cycle. if the oversampling is 8 (over at 1), a start bit is detected at the fourth sample at 0. then, data bits, parity bit and stop bit are sampled on each 8 sampling clock cycle. the number of data bits, first bit sent and parity mode are selected by the same fields and bits as the transmitter, i.e. respectively chrl , mode9, msbf and par. for the synchronization mechanism only , the number of stop bits has no effect on the receiver as it considers only one stop bit, regardless of the field nbstop, so that resynchronization between the receiver and the transmitter can occur. moreover, as soon as the st op bit is sampled, the receiver starts looking for a new start bit so that resynchronization can also be accomplished when the transmitter is operating with one stop bit. figure 25-11 and figure 25-12 illustrate start detection and character reception when usart operates in asynchronous mode. figure 25-11. asynchronous start detection figure 25-12. asynchronous character reception sampling clock (x16) rxd start detection sampling baud rate clock rxd start rejection sampling 12345678 12345670 1234 12345678 9 10111213141516 d0 sampling d0 d1 d2 d3 d4 d5 d6 d7 rxd parity bit stop bit example: 8-bit, parity enabled baud rate clock start detection 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples
560 32072d?04/2011 at32uc3a3/a4 25.6.3.4 manchester decoder when the man field in mr register is set to 1, the manchester decoder is enabled. the decoder performs both preamble and start frame delimiter detection. one input line is dedicated to man- chester encoded input data. an optional preamble sequence can be defined, it s length is user-defined and totally indepen- dent of the emitter side. use rx_pl in man regi ster to configure the length of the preamble sequence. if the length is set to 0, no preamble is detected and the function is disabled. in addi- tion, the polarity of the input stream is programmable with rx_mpol field in man register. depending on the desired application the preamble pattern matching is to be defined via the rx_pp field in man. see figure 25-8 for available preamble patterns. unlike preamble, the start frame delimiter is shared between manchester encoder and decoder. so, if onebit field is set to 1, only a zero encoded manchester can be detected as a valid start frame delimiter. if onebit is set to 0, only a sync pattern is detected as a valid start frame delimiter. decoder operates by detecting transition on incoming stream. if rxd is sampled dur- ing one quarter of a bit time at zero, a start bit is detected. see figure 25-13 . the sample pulse rejection mechanism applies. figure 25-13. asynchronous star t bit detection the receiver is activated and starts preamble and frame delimiter detection, sampling the data at one quarter and then three quarters. if a valid preamble pattern or start frame delimiter is detected, the receiver continues decoding with the same synchronization. if the stream does not match a valid pattern or a valid start frame delimiter, the receiver re-synchronizes on the next valid edge.the minimum time threshold to estimate the bit value is three quarters of a bit time. if a valid preamble (if used) followed with a valid start frame delimiter is detected, the incoming stream is decoded into nrz data and passed to usart for processing. figure 25-14 illustrates manchester pattern mismatch. when incoming data stream is passed to the usart, the receiver is also able to detect manchester code vi olation. a code violation is a lack of transition in the middle of a bit cell. in this case, mane flag in csr register is raised. it is cleared by writing the control register (cr) with the rststa bit at 1. see figure 25-15 for an example of man- chester error detection during data phase. manchester encoded data txd 1234 sampling clock (16 x) start detection
561 32072d?04/2011 at32uc3a3/a4 figure 25-14. preamble pattern mismatch figure 25-15. manchester error flag when the start frame delimiter is a sync pattern (onebit field at 0), both command and data delimiter are supported. if a valid sync is detec ted, the received character is written as rxchr field in the rhr register and the rxsynh is updated. rxchr is set to 1 when the received character is a command, and it is set to 0 if the received character is a data. this mechanism alleviates and simplifies the direct memory access as the character contains its own sync field in the same register. as the decoder is setup to be used in unipolar mode, the first bit of the frame has to be a zero-to- one transition. 25.6.3.5 radio interface: manchester encoded usart application this section describes low data rate rf transm ission systems and their integration with a man- chester encoded usart. these systems are based on transmitter and receiver ics that support ask and fsk modulation schemes. the goal is to perform full duplex radio transmissi on of characters using two different frequency carriers. see the configuration in figure 25-16 . manchester encoded data txd sfd data preamble length is set to 8 preamble mismatch invalid pattern preamble mismatch manchester coding error manchester encoded data txd sfd preamble length is set to 4 elementary character bit time manchester coding error detected sampling points preamble subpacket and start frame delimiter were successfully decoded entering usart character area
562 32072d?04/2011 at32uc3a3/a4 figure 25-16. manchester encoded characters rf transmission the usart module is configured as a manchester encoder/decoder. looking at the down- stream communication channel, manchester encoded characters are serially sent to the rf emitter. this may also include a user defined preamble and a start frame delimiter. mostly, pre- amble is used in the rf receiver to distinguish between a valid data from a transmitter and signals due to noise. the manchester stream is then modulated. see figure 25-17 for an exam- ple of ask modulation scheme. when a logic one is sent to the ask modulator, the power amplifier, referred to as pa, is enabled and transmits an rf signal at downstream frequency. when a logic zero is transmitted, the rf signal is turned off. if the fsk modulator is activated, two different frequencies are used to transmit dat a. when a logic 1 is sent, the modulator out- puts an rf signal at frequency f0 and switches to f1 if the data sent is a 0. see figure 25-18 . from the receiver side, another carrier frequency is used. the rf receiver performs a bit check operation examining demodulated data stream. if a valid pattern is detected, the receiver switches to receiving mode. the demodulated stream is sent to the manchester decoder. because of bit checking inside rf ic, the data transferred to the microcontroller is reduced by a user-defined number of bits. the manchester preamble length is to be defined in accordance with the rf ic configuration. figure 25-17. ask modulator output lna vco rf filter demod control bi-dir line pa rf filter mod vco control manchester decoder manchester encoder usart receiver usart emitter ask/fsk upstream receiver ask/fsk downstream transmitter upstream emitter downstream receiver serial configuration interface fup frequency carrier fdown frequency carrier manchester encoded data default polarity unipolar output txd ask modulator output uptstream frequency f0 nrz stream 10 0 1
563 32072d?04/2011 at32uc3a3/a4 figure 25-18. fsk modulator output 25.6.3.6 synchronous receiver in synchronous mode (sync = 1), the receiver samples the rxd signal on each rising edge of the baud rate clock. if a lo w level is detected, it is considered as a start. all data bits, the parity bit and the stop bits are sampled and the receiver waits for the next start bit. synchronous mode operations provide a high speed transfer capability. configuration fields and bits are the same as in asynchronous mode. figure 25-19 illustrates a character rec eption in synchronous mode. figure 25-19. synchronous mode character reception 25.6.3.7 receiver operations when a character reception is completed, it is transferred to the receive holding register (rhr) and the rxrdy bit in the st atus register (csr) rises. if a character is completed while the rxrdy is set, the ovre (overrun error) bit is set. the last character is transferred into rhr and overwrites the previous one. the ovre bit is cleared by writing the control register (cr) with the rststa (reset status) bit at 1. manchester encoded data default polarity unipolar output txd fsk modulator output uptstream frequencies [f0, f0+offset] nrz stream 10 0 1 d0 d1 d2 d3 d4 d5 d6 d7 rxd start sampling parity bit stop bit example: 8-bit, parity enabled 1 stop baud rate clock
564 32072d?04/2011 at32uc3a3/a4 figure 25-20. receiver status d0 d1 d2 d3 d4 d5 d6 d7 rxd start bit parity bit stop bit baud rate clock write cr rxrdy ovre d0 d1 d2 d3 d4 d5 d6 d7 start bit parity bit stop bit rststa = 1 read rhr
565 32072d?04/2011 at32uc3a3/a4 25.6.3.8 parity the usart supports five parity modes selected by programming the par field in the mode register (mr). the par field also enables the multidrop mode, see ?multidrop mode? on page 566 . even and odd parity bit generation and error detection are supported. if even parity is selected, the parity generator of the transmitter drives the parity bit at 0 if a num- ber of 1s in the character data bit is even, and at 1 if the number of 1s is odd. accordingly, the receiver parity checker counts the number of received 1s and reports a parity error if the sam- pled parity bit does not correspond. if odd parity is selected, the parity generator of the transmitter drives the parity bit at 1 if a number of 1s in the character data bit is even, and at 0 if the number of 1s is odd. accordingly, the receiver parity checker counts the number of received 1s and reports a parity error if the sampled parity bit does not correspond. if the mark parity is used, the parity generator of the transmitter drives the parity bit at 1 for all characters. the receiver parity checker reports an error if the parity bit is sampled at 0. if the space parity is used, the parity generator of the transmitter drives the parity bit at 0 for all characters. the receiver parity checker reports an error if the parity bit is sampled at 1. if parity is disabled, the transmitter does not generate any parity bit and the receiver does not report any parity error. table 25-7 shows an example of the parity bit for the character 0x41 (character ascii ?a?) depending on the configuration of the usart. because there are two bits at 1, 1 bit is added when a parity is odd, or 0 is added when a parity is even. when the receiver detects a parity error, it sets the pare (parity error) bit in the channel status register (csr). the pare bit can be cleared by writing the control register (cr) with the rst- sta bit at 1. figure 25-21 illustrates the parity bit status setting and clearing. table 25-7. parity bit examples character hexa binary parity bit parity mode a 0x41 0100 0001 1 odd a 0x41 0100 0001 0 even a 0x41 0100 0001 1 mark a 0x41 0100 0001 0 space a 0x41 0100 0001 none none
566 32072d?04/2011 at32uc3a3/a4 figure 25-21. parity error 25.6.3.9 multidrop mode if the par field in the mode register (mr) is programmed to the value 0x6 or 0x07, the usart runs in multidrop mode. this mode differentia tes the data characters and the address charac- ters. data is transmitted with the parity bit at 0 and addresses are transmitted with the parity bit at 1. if the usart is configured in multidrop mode, the receiver sets the pare parity error bit when the parity bit is high and the transmitter is able to send a character with the parity bit high when the control register is written with the senda bit at 1. to handle parity error, the pare bit is cleared when the control register is written with the bit rststa at 1. the transmitter sends an address byte (parity bit set) when senda is written to cr. in this case, the next byte written to thr is transmitted as an address. any character written in thr without having written the command senda is transmitted normally with the parity at 0. 25.6.3.10 transmitter timeguard the timeguard feature enables the usar t interface with slow remote devices. the timeguard function enables the transmitter to insert an idle state on the txd line between two characters. this idle state actually acts as a long stop bit. the duration of the idle state is programmed in the tg field of the transmitter timeguard regis- ter (ttgr). when this field is programmed at zero no timeguard is generated. otherwise, the transmitter holds a high level on txd after each transmitted byte during the number of bit peri- ods programmed in tg in addition to the number of stop bits. as illustrated in figure 25-22 , the behavior of txrdy and txempty status bits is modified by the programming of a timeguard. txrdy rises only when the start bit of the next character is sent, and thus remains at 0 during the timeguard transmission if a character has been written in thr. txempty remains low until the timeguard transmission is completed as the timeguard is part of the current character being transmitted. d0 d1 d2 d3 d4 d5 d6 d7 rxd start bit bad parity bit stop bit baud rate clock write cr pare rxrdy rststa = 1
567 32072d?04/2011 at32uc3a3/a4 figure 25-22. timeguard operations table 25-8 indicates the maximum length of a timeguard period that the transmitter can handle in relation to the function of the baud rate. 25.6.3.11 receiver time-out the receiver time-out provides support in handling variable-length frames. this feature detects an idle condition on the rxd line. when a time-out is detected, the bit timeout in the channel status register (csr) rises and can generate an interrupt, thus indicating to the driver an end of frame. the time-out delay period (during which the receiver waits for a new character) is programmed in the to field of the receiver time-out register (rtor). if the to field is programmed at 0, the receiver time-out is disabled and no time-out is detected. the timeou t bit in csr remains at 0. otherwise, the receiver loads a counter with the value programmed in to. this counter is decremented at each bit period and reloaded each time a new character is received. if the coun- ter reaches 0, the timeout bit in the status register rises. then, the user can either: ? stop the counter clock until a new character is received. this is performed by writing the control register (cr) with the sttto (start time-out) bit at 1. in this case, the idle state on rxd before a new character is received will not provide a time-out. this prevents having to d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit b aud rate clock start bit tg = 4 write thr d0 d1 d2 d3 d4 d5 d6 d7 parity bit stop bit txrdy t xempty tg = 4 table 25-8. maximum timeguard length depending on baud rate baud rate bit time timeguard bit/sec s ms 1 200 833 212.50 9 600 104 26.56 14400 69.4 17.71 19200 52.1 13.28 28800 34.7 8.85 33400 29.9 7.63 56000 17.9 4.55 57600 17.4 4.43 115200 8.7 2.21
568 32072d?04/2011 at32uc3a3/a4 handle an interrupt before a character is received and allows waiting for the next idle state on rxd after a fram e is received. ? obtain an interrupt while no character is receiv ed. this is performed by writing cr with the retto (reload and start time-out) bit at 1. if retto is performed, the counter starts counting down immediately from the value to. this enables generation of a periodic interrupt so that a user time-out can be handled, for example when no key is pressed on a keyboard. if sttto is performed, the counter clock is stopped until a first character is received. the idle state on rxd before the start of the frame does not provide a time-out. this prevents having to obtain a periodic interrupt and enables a wait of the end of frame when the idle state on rxd is detected. if retto is performed, the counter starts counting down immediately from the value to. this enables generation of a periodic interrupt so t hat a user time-out can be handled, for example when no key is pressed on a keyboard. figure 25-23 shows the block diagram of the receiver time-out feature. figure 25-23. receiver time-o ut block diagram table 25-9 gives the maximum time-out period for some standard baud rates. table 25-9. maximum time-out period baud rate bit time time-out bit/sec s ms 600 1 667 109 225 1 200 833 54 613 2 400 417 27 306 4 800 208 13 653 9 600 104 6 827 14400 69 4 551 19200 52 3 413 28800 35 2 276 33400 30 1 962 16-bit time-out counter 0 to timeout baud rate clock = character received retto load clock 16-bit value sttto dq 1 clear
569 32072d?04/2011 at32uc3a3/a4 25.6.3.12 framing error the receiver is capable of detecting framing errors. a framing error happens when the stop bit of a received character is detected at level 0. this can occur if the receiver and the transmitter are fully desynchronized. a framing error is reported on the frame bit of the channel status register (csr). the frame bit is asserted in the middle of the stop bit as soon as the framing error is detected. it is cleared by writing the control register (cr) with the rststa bit at 1. figure 25-24. framing error status 25.6.3.13 transmit break the user can request the transmitter to generate a break condition on the txd line. a break con- dition drives the txd line low during at least one complete character. it appears the same as a 0x00 character sent with the parity and the stop bits at 0. however, the transmitter holds the txd line at least during one character until the user requests the break condition to be removed. a break is transmitted by writing the control register (cr) with the sttbrk bit at 1. this can be performed at any time, either while the transmitter is empty (no character in either the shift reg- ister or in thr) or when a character is being transmitted. if a break is requested while a character is being shifted out, t he character is first completed be fore the txd line is held low. once sttbrk command is requested further sttbrk commands are ignored until the end of the break is completed. the break condition is removed by writing cr with the stpbrk bit at 1. if the stpbrk is requested before the end of the minimum break duration (one character, including start, data, parity and stop bits), the transmitter ensures that the break condition completes. 56000 18 1 170 57600 17 1 138 200000 5 328 table 25-9. maximum time-out period (continued) baud rate bit time time-out d0 d1 d2 d3 d4 d5 d6 d7 rxd start bit parity bit stop bit baud rate clock write cr frame rxrdy rststa = 1
570 32072d?04/2011 at32uc3a3/a4 the transmitter considers the break as though it is a character, i.e. the sttbrk and stpbrk commands are taken into account only if the txrdy bit in csr is at 1 and the start of the break condition clears the txrdy and txempty bits as if a character is processed. writing cr with the both sttbrk and stpbrk bits at 1 can lead to an unpredictable result. all stpbrk commands requested without a previous sttbrk command are ignored. a byte writ- ten into the transmit holding re gister while a break is pending, but not started, is ignored. after the break condition, the transmitter returns the txd line to 1 for a minimum of 12 bit times. thus, the transmitter ensures that the remote receiver detects correctly the end of break and the start of the next character. if the timeguard is programmed with a value higher than 12, the txd line is held high for the timeguard period. after holding the txd line for this period, the transmitter resumes normal operations. figure 25-25 illustrates the effect of both the start break (sttbrk ) and stop break (stpbrk) commands on the txd line. figure 25-25. break transmission 25.6.3.14 receive break the receiver detects a break condition when all data, parity and stop bits are low. this corre- sponds to detecting a framing error with data at 0x00, but frame remains low. when the low stop bit is detected, the receiver asserts the rxbrk bit in csr. this bit may be cleared by writing the control register (cr) with the bit rststa at 1. an end of receive break is detected by a high leve l for at least 2/16 of a bit period in asynchro- nous operating mode or one sample at high level in synchronous operating mode. the end of break detection also asserts the rxbrk bit. 25.6.3.15 hardware handshaking the usart features a hardware handshaking out-of-band flow control. the rts and cts pins are used to connect with the remote device, as shown in figure 25-26 . d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit baud rate clock write cr txrdy txempty stpbrk = 1 sttbrk = 1 break transmission end of break
571 32072d?04/2011 at32uc3a3/a4 figure 25-26. connection with a remote device for hardware handshaking setting the usart to operate with hardware handshaking is performed by writing the mode field in the mode register (mr) to the value 0x2. the usart behavior when hardware handshaking is enabled is the same as the behavior in standard synchronous or asynchronous mode, except that the receiver drives the rts pin as described below and the level on the cts pin modifies the behavior of the transmitter as described below. using this m ode requires using the peripheral dma controller channel for reception. the transmitter can handle hardware handshaking in any case. figure 25-27 shows how the receiver operates if hardware handshaking is enabled. the rts pin is driven high if the receiver is disabled and if the status rxbuff (receive buffer full) com- ing from the peripheral dma controller channel is high. normally, the remote device does not start transmitting while it s cts pin (driven by rts) is high. as soon as the receiver is enabled, the rts falls, indicating to the remote device that it can start transmitting. defining a new buffer to the peripheral dma controller clears the status bit rxbuff and, as a result, asserts the pin rts low. figure 25-27. receiver behavior when operating with hardware handshaking figure 25-28 shows how the transmitter operates if hardware handshaking is enabled. the cts pin disables the transmitt er. if a character is being processi ng, the transmitter is disabled only after the completion of the current character and transmission of the next character happens as soon as the pin cts falls. figure 25-28. transmitter behavior when operating with hardware handshaking usart txd cts remote device rxd txd rxd rts rts cts rts r xbuff write cr rxen = 1 rxd rxdis = 1 cts txd
572 32072d?04/2011 at32uc3a3/a4 25.6.4 iso7816 mode the usart features an iso7816-compatible operating mode. this mode permits interfacing with smart cards and security access modules (sam) communicating through an iso7816 link. both t = 0 and t = 1 protocols defined by the iso7816 specification are supported. setting the usart in iso7816 mode is performed by writing the mode field in the mode regis- ter (mr) to the value 0x4 for protocol t = 0 and to the value 0x6 for protocol t = 1. 25.6.4.1 iso7816 mode overview the iso7816 is a half duplex communication on only one bidirectional line. the baud rate is determined by a division of the clo ck provided to the remote device (see ?baud rate generator? on page 550 ). the usart connects to a smart card as shown in figure 25-29 . the txd line becomes bidirec- tional and the baud rate generator feeds the iso7816 clock on the clk pin. as the txd pin becomes bidirectional, its output remains driven by the output of the transmitter but only when the transmitter is active while its input is direct ed to the input of the receiver. the usart is con- sidered as the master of the communication as it generates the clock. figure 25-29. connection of a smart card to the usart when operating in iso7816, either in t = 0 or t = 1 modes, the character format is fixed. the configuration is 8 data bits, ev en parity and 1 or 2 stop bits, regardless of the values pro- grammed in the chrl, mode9, par and chmode fields. msbf can be used to transmit lsb or msb first. parity bit (par) can be used to transmit in normal or inverse mode. refer to ?mode register? on page 608 and ?par: parity type? on page 609 . the usart cannot operate concurrently in both receiver and transmitter modes as the commu- nication is unidirectional at a time. it has to be configured according to the required mode by enabling or disabling either the receiver or the transmitter as desired. enabling both the receiver and the transmitter at the same time in iso7816 mode may lead to unpredictable results. the iso7816 specification defines an inverse transmission format. data bits of the character must be transmitted on the i/o line at their negative value. the usart does not support this for- mat and the user has to perform an exclusive or on the data before writing it in the transmit holding register (thr) or after reading it in the receive holding register (rhr). 25.6.4.2 protocol t = 0 in t = 0 protocol, a character is made up of one start bit, eight data bits, one parity bit and one guard time, which lasts two bit times. the transmitter shifts out the bits and does not drive the i/o line during the guard time. if no parity error is detected, the i/o line remains at 1 during the guard time and the transmitter can continue with the transmission of the next character, as shown in figure 25-30 . clk txd usart clk i/o smart card
573 32072d?04/2011 at32uc3a3/a4 if a parity error is detected by the receiver, it drives the i/o line at 0 during the guard time, as shown in figure 25-31 . this error bit is also named nack, for non acknowledge. in this case, the character lasts 1 bit time more, as the guard time length is the same and is added to the error bit time which lasts 1 bit time. when the usart is the receiver and it detects an error, it does not load the erroneous character in the receive holding register (rhr). it appropriately sets the pare bit in the status register (sr) so that the software can handle the error. figure 25-30. t = 0 protocol without parity error figure 25-31. t = 0 protocol with parity error 25.6.4.3 receive error counter the usart receiver also records the total number of errors. this can be read in the number of error (ner) register. the nb_errors field ca n record up to 255 errors. reading ner auto- matically clears the nb_errors field. 25.6.4.4 receive nack inhibit the usart can also be configured to inhibit an error. this can be achieved by setting the inack bit in the mode register (mr). if inack is at 1, no error signal is driven on the i/o line even if a parity bit is detected. moreover, if inack is set, the erroneous receiv ed character is stored in the receive holding register, as if no error occurred. however, the rxrdy bit does raise. 25.6.4.5 transmit character repetition when the usart is transmitting a character and gets a nack, it can automatically repeat the character before moving on to the next one. repetition is enabled by writing the max_iteration field in the mode register (mr) at a value higher than 0. each character can be transmitted up to eight times; the firs t transmission plus seven repetitions. if max_iteration does not equal zero, the u sart repeats the character as many times as the value loaded in max_iteration. when the usart repetition number reaches max_iteration, the iteration bit is set in the channel status register (csr). if the repetition of the character is acknowledged by the receiver, the repetitions are stopped and the iteration counter is cleared. d0 d1 d2 d3 d4 d5 d6 d7 rxd parity bit baud rate clock start bit guard time 1 next start bit guard time 2 d0 d1 d2 d3 d4 d5 d6 d7 i/o parity bit baud rate clock start bit guard time 1 start bit guard time 2 d0 d1 error repetition
574 32072d?04/2011 at32uc3a3/a4 the iteration bit in csr can be cleared by writing the control register with the rsit bit at 1. 25.6.4.6 disable successive receive nack the receiver can limit the number of successive nacks sent back to the remote transmitter. this is programmed by setting the bit dsnack in the mode register (mr). the maximum num- ber of nack transmitted is programmed in the max_iteration field. as soon as max_iteration is reached, the character is cons idered as correct, an acknowledge is sent on the line and the iteration bit in the channel status register is set. 25.6.4.7 protocol t = 1 when operating in iso7816 protocol t = 1, the transmission is similar to an asynchronous for- mat with only one stop bit. the parity is generated when transmitting and checked when receiving. parity error detection sets the par e bit in the channel status register (csr). 25.6.5 irda mode the usart features an irda mode supplying half-duplex point-to-point wireless communica- tion. it embeds the modulator and demodulator which allows a glueless connection to the infrared transceivers, as shown in figure 25-32 . the modulator and demodulator are compliant with the irda specification version 1.1 and support data transfer speeds ranging from 2.4 kb/s to 115.2 kb/s. the usart irda mode is enabled by setting the mo de field in the mode register (mr) to the value 0x8. the irda filter register (ifr) allo ws configuring the demodulator filter. the usart transmitter and receiver operate in a normal asynchronous mode and all parameters are acces- sible (except those fixed by irda specification: one start bit, 8 data bits and one stop bit). note that the modulator and the demodulator are activated. figure 25-32. connection to irda transceivers the receiver and the transmitter must be enabled or disabled according to the direction of the transmission to be managed. to receive irda signals, the following needs to be done: ? disable tx and enable rx ? configure the txd pin as i/o and set it as an output at 0 (to avoid led emission). disable the internal pull-up (better for power consumption). ? receive data irda transceivers rxd rx txd tx usart demodulator modulator receiver transmitter
575 32072d?04/2011 at32uc3a3/a4 25.6.5.1 irda modulation for baud rates up to and including 115.2 kbits/sec, the rzi modulation scheme is used. ?0? is represented by a light pulse of 3/16th of a bit time. some examples of signal pulse duration are shown in table 25-10 . figure 25-33 shows an example of character transmission. figure 25-33. irda modulation 25.6.5.2 irda baud rate table 25-11 gives some examples of cd values, baud rate error and pulse duration. note that the requirement on the maximum acceptable error of 1.87% must be met. table 25-10. irda pulse duration baud rate pulse duration (3/16) 2.4 kb/s 78.13 s 9.6 kb/s 19.53 s 19.2 kb/s 9.77 s 38.4 kb/s 4.88 s 57.6 kb/s 3.26 s 115.2 kb/s 1.63 s bit period bit period 3 16 start bit data bits stop bit 0 0 0 0 0 1 1 1 1 1 transmitter output txd table 25-11. irda baud rate error peripheral clock baud rate cd baud rate error pulse time 3 686 400 115 200 2 0.00% 1.63 20 000 000 115 200 11 1.38% 1.63 32 768 000 115 200 18 1.25% 1.63 40 000 000 115 200 22 1.38% 1.63 3 686 400 57 600 4 0.00% 3.26 20 000 000 57 600 22 1.38% 3.26 32 768 000 57 600 36 1.25% 3.26 40 000 000 57 600 43 0.93% 3.26 3 686 400 38 400 6 0.00% 4.88 20 000 000 38 400 33 1.38% 4.88
576 32072d?04/2011 at32uc3a3/a4 25.6.5.3 irda demodulator the demodulator is based on the irda receive filter co mprised of an 8-bit down counter which is loaded with the value programmed in ifr. when a falling edge is detected on the rxd pin, the filter counter starts counting down at the clk_usart speed. if a rising edge is detected on the rxd pin, the counter stops and is reloaded with ifr. if no rising edge is detected when the counter reaches 0, the input of the receiver is driven low during one bit time. figure 25-34 illustrates the operations of the irda demodulator. figure 25-34. irda demodulator operations as the irda mode uses the same logic as the iso7816, note that the fi_di_ratio field in fidi must be set to a value higher than 0 in order to assure irda communications operate correctly. 32 768 000 38 400 53 0.63% 4.88 40 000 000 38 400 65 0.16% 4.88 3 686 400 19 200 12 0.00% 9.77 20 000 000 19 200 65 0.16% 9.77 32 768 000 19 200 107 0.31% 9.77 40 000 000 19 200 130 0.16% 9.77 3 686 400 9 600 24 0.00% 19.53 20 000 000 9 600 130 0.16% 19.53 32 768 000 9 600 213 0.16% 19.53 40 000 000 9 600 260 0.16% 19.53 3 686 400 2 400 96 0.00% 78.13 20 000 000 2 400 521 0.03% 78.13 32 768 000 2 400 853 0.04% 78.13 table 25-11. irda baud rate error (continued) peripheral clock baud rate cd baud rate error pulse time clk_usart rxd counter value receiver input 654 6 3 pulse rejected 264 53210 pulse accepted driven low during 16 baud rate clock cycles
577 32072d?04/2011 at32uc3a3/a4 25.6.6 rs485 mode the usart features the rs485 mode to enable li ne driver control. while operating in rs485 mode, the usart behaves as though in asynch ronous or synchronous mode and configuration of all the parameters is possible. the differenc e is that the rts pin is driven high when the transmitter is operating. the behavior of the rts pin is controlled by the txempty bit. a typical connection of the usart to a rs485 bus is shown in figure 25-35 . figure 25-35. typical connection to a rs485 bus the usart is set in rs485 mode by programming the mode field in the mode register (mr) to the value 0x1. the rts pin is at a level inverse to the txempt y bit. significantly, the rts pin remains high when a timeguard is programmed so that the line can remain driven after the last character com- pletion. figure 25-36 gives an example of the rts waveform during a character transmission when the timeguard is enabled. figure 25-36. example of rts drive with timeguard usart rts txd rxd differential bus d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit baud rate clock tg = 4 write thr txrdy txempty rts
578 32072d?04/2011 at32uc3a3/a4 25.6.7 modem mode the usart features modem mode, which enables control of the signals: dtr (data terminal ready), dsr (data set ready), rts (request to send), cts (clear to send), dcd (data car- rier detect) and ri (ring indicator). while operating in modem mode, the usart behaves as a dte (data terminal equipment) as it drives dtr and rts and can detect level change on dsr, dcd, cts and ri. setting the usart in modem mode is performed by writing the mode field in the mode regis- ter (mr) to the value 0x3. while operating in modem mode the usart behaves as though in asynchronous mode and all the parameter configurations are available. table 25-12 gives the correspondence of the usart signals with modem connection standards. the control of the dtr output pin is performed by writing the control register (cr) with the dtrdis and dtren bits respectively at 1. th e disable command forces the corresponding pin to its inactive level, i.e. high. the enable command forces the corresponding pin to its active level, i.e. low. rts ou tput pin is automatically controlled in this mode the level changes are detected on the ri, dsr, dcd and cts pins. if an input change is detected, the riic, dsric, dcdic and ctsic bits in the channel status register (csr) are set respectively and can trigger an interrupt. the st atus is automatically cleared when csr is read. furthermore, the cts automatically disables the transmitter when it is detected at its inactive state. if a character is being transmitted when the cts rises, the character transmission is com- pleted before the transmitter is actually disabled. table 25-12. circuit references usart pin v24 ccitt direction txd 2 103 from terminal to modem rts 4 105 from terminal to modem dtr 20 108.2 from terminal to modem rxd 3 104 from modem to terminal cts 5 106 from terminal to modem dsr 6 107 from terminal to modem dcd 8 109 from terminal to modem ri 22 125 from terminal to modem
579 32072d?04/2011 at32uc3a3/a4 25.6.8 spi mode the serial peripheral interface (spi) mode is a synchronous serial data link that provides com- munication with external devices in master or slave mode. it also enables communication between processors if an external processor is connected to the system. the serial peripheral interface is essentially a shift register that serially transmits data bits to other spis. during a data transfer, one spi system acts as the ?master? which controls the data flow, while the other devices act as ?slaves'' whic h have data shifted into and out by the master. different cpus can take turns being masters and one master may simultaneously shift data into multiple slaves. (multiple master protocol is the opposite of single master protocol, where one cpu is always the master while all of the others are always slaves.) however, only one slave may drive its output to write data back to the master at any given time. a slave device is selected when its nss signal is asserted by the master. the usart in spi master mode can address only one spi slave bec ause it can generate only one nss signal. nevertheless the user can use standard i/o lines to access more than one spi slave. the spi system consists of two data lines and two control lines: ? master out slave in (mosi): this data line supplies the output data from the master shifted into the input of the slave. ? master in slave out (miso): this data line supplies the output data from a slave to the input of the master. ? serial clock (clk): this control line is driven by the master and regulates the flow of the data bits. the master may transmit data at a variety of baud rates. the clk line cycles once for each bit that is transmitted. ? slave select (nss): this control line allows the master to select or deselect the slave. 25.6.8.1 modes of operation the usart can operate in master mode or in slave mode. operation in spi master mode is programmed by writing at 0xe the mode field in the mode register. in this case the spi lines must be connected as described below: ? the mosi line is driven by the output pin txd ? the miso line drives the input pin rxd ? the clk line is driven by the output pin clk ? the nss line is driven by the output pin rts operation in spi slave mode is programmed by writing at 0xf the mode field in the mode reg- ister. in this case the spi lines must be connected as described below: ? the mosi line drives the input pin rxd ? the miso line is driven by the output pin txd ? the clk line drives the input pin clk ? the nss line drives the input pin cts in order to avoid unpredicted behavior, any change of the spi mode must be followed by a soft- ware reset of the transmitter and of the receiver (except the initial configuration after a hardware reset).
580 32072d?04/2011 at32uc3a3/a4 25.6.8.2 baud rate in spi mode, the baudrate generator operates in the same way as in usart synchronous mode: see section ?25.6.1.4? on page 552. however, there are some restrictions: in spi master mode: ? the external clock clk must not be selected (usclks 0x3), and the bit clko must be set to ?1? in the mode register (mr), in order to generate correctly the serial clock on the clk pin. ? to obtain correct behavior of the receiver and the transmitter, the value programmed in cd of must be superior or equal to 4. ? if the internal clock divided (clk_usart/div) is selected, the value programmed in cd must be even to ensure a 50:50 mark/space ratio on the clk pin, this value can be odd if the internal clock is selected (clk_usart). in spi slave mode: ? the external clock (clk) selection is forced regardless of the value of the usclks field in the mode register (mr). likewise, the value written in brgr has no effect, because the clock is provided directly by the signal on the usart clk pin. ? to obtain correct behavior of the receiver and the transmitter, the external clock (clk) frequency must be at least 4 times lower than the system clock.
581 32072d?04/2011 at32uc3a3/a4 25.6.8.3 data transfer up to 9 data bits are successively shifted out on the txd pin at each rising or falling edge (depending of cpol and cpha) of the programmed serial clock. there is no start bit, no parity bit and no stop bit. the number of data bits is selected by the chrl field and the mode 9 bit in the mode register (mr). the 9 bits are se lected by setting the mode 9 bit re gardless of the chrl field. the msb data bit is always sent first in spi mode (master or slave). four combinations of polarity and phase are available for data transfers. the clock polarity is programmed with the cpol bit in the mode regi ster. the clock phase is programmed with the cpha bit. these two parameters determine the edges of the clock signal upon which data is driven and sampled. each of the two parameters has two possible states, resulting in four possi- ble combinations that are incompatible with one another. thus, a master/slave pair must use the same parameter pair values to communicate. if multiple slaves are used and fixed in different configurations, the master must reconfigure itself each time it needs to communicate with a dif- ferent slave. table 25-13. spi bus protocol mode spi bus protocol mode cpol cpha 001 100 211 310
582 32072d?04/2011 at32uc3a3/a4 figure 25-37. spi transfer format (cpha=1, 8 bits per transfer) figure 25-38. spi transfer format (cpha=0, 8 bits per transfer) clk cycle (for reference) clk (cpol= 1) mosi spi master ->txd spi slave ->rxd miso spi master ->rxd spi slave ->txd nss spi master ->rts spi slave ->cts msb msb 1 clk (cpol= 0) 3 5 6 78 lsb 1 2 3 4 6 65 5 43 21 lsb 24 clk cycle (for reference) clk (cpol= 0) clk (cpol= 1) mosi spi master -> txd spi slave -> rxd miso spi master -> rxd spi slave -> txd nss spi master -> rts spi slave -> cts msb 6 5 msb 6 5 4 43 32 21 1 lsb lsb 8 7 6 5 4 3 2 1
583 32072d?04/2011 at32uc3a3/a4 25.6.8.4 receiver and transmitter control see section ?25.6.2? on page 554. 25.6.8.5 character transmission the characters are sent by writing in the tr ansmit holding register (thr). the transmitter reports two status bits in the channel status register (csr): txrdy (transmitter ready), which indicates that thr is empt y and txempty, which indicates that all the characters written in thr have been processed. when the current character processing is completed, the last character written in thr is transferred into the shift register of the transmitter and thr becomes empty, thus txrdy rises. both txrdy and txempty bits are low when the transmitter is disabled. writing a character in thr while txrdy is low has no effect and the written character is lost. if the usart is in spi slave mode and if a character must be sent while the transmit holding register (thr) is empty, the unre (underrun error) bit is set. the txd transmission line stays at high level during all this time. the unre bit is cleared by writing the control register (cr) with the rststa (reset status) bit at 1. in spi master mode, the slave select line (nss) is asserted at low level 1 tbit before the trans- mission of the msb bit and released at high level 1 tbit after the transmission of the lsb bit. so, the slave select line (nss) is always released be tween each character transmission and a mini- mum delay of 3 tbits always inserted. however, in order to address slave devices supporting the csaat mode (chip select active after transfer), the slave select line (nss) can be forced at low level by writing the control register (cr) with the rtsen bit at 1. the slave select line (nss) can be released at high level only by wr iting the control register (cr) with the rtsdis bit at 1 (for example, when all data have been transferred to the slave device). in spi slave mode, the transmitter does not require a falling edge of the slave select line (nss) to initiate a character transmission but only a low level. however, this lo w level must be present on the slave select line (nss) at least 1 tbit before the first serial clock cycle corresponding to the msb bit. 25.6.8.6 character reception when a character reception is completed, it is transferred to the receive holding register (rhr) and the rxrdy bit in the st atus register (csr) rises. if a character is completed while rxrdy is set, the ovre (overrun error) bit is set. the last character is transferred into rhr and overwrites the previous one. the ovre bit is cleared by writing the control register (cr) with the rststa (reset status) bit at 1. to ensure correct behavior of the receiver in spi slave mode, the master device sending the frame must ensure a minimum delay of 1 tb it between each character transmission. the receiver does not require a falling edge of the slave select line (nss) to initiate a character reception but only a low level. however, this low level must be present on the slave select line (nss) at least 1 tbit before the first serial clock cycle corresponding to the msb bit. 25.6.8.7 receiver time-out because the receiver baudrate clock is active only during data transfers in spi mode, a receiver time-out is impossible in this mode, whatever the time-out valu e is (field to) in the time-out register (rtor).
584 32072d?04/2011 at32uc3a3/a4 25.6.9 lin mode the lin mode provides master node and slave node connectivity on a lin bus. the lin (local interconnect network) is a serial communication protocol which efficiently sup- ports the control of mechatronic nodes in distributed automotive applications. the main properties of the lin bus are: ? single master/multiple slaves concept ? low cost silicon implementation based on common uart/sci interface hardware, an equivalent in software, or as a pure state machine. ? self synchronization without quartz or ceramic resonator in the slave nodes ? deterministic signal transmission ? low cost single-wire implementation ? speed up to 20 kbit/s lin provides cost efficient bu s communication where the bandwid th and versatility of can are not required. the lin mode enables processing lin frames with a minimum of action from the microprocessor. 25.6.9.1 modes of operation the usart can act either as a lin master node or as a lin slave node. the node configuration is chosen by setting the mode field in the mode register (mr): ? lin master node (mode=0xa) ? lin slave node (mode=0xb) in order to avoid unpredicted behavior, any change of the lin node configuration must be fol- lowed by a software reset of the transmitter and of the receiver (except the initial node configuration after a hardware reset). (see section 25.6.9.2 ) 25.6.9.2 receiver and transmitter control see section ?25.6.2? on page 554. 25.6.9.3 character transmission see section ?25.6.3.1? on page 555. 25.6.9.4 character reception see section ?25.6.3.7? on page 563.
585 32072d?04/2011 at32uc3a3/a4 25.6.9.5 header transmission (master node configuration) all the lin frames start with a header which is sent by the master node and consists of a synch break field, synch field and identifier field. so in master node configuration, the frame handling starts with the sending of the header. the header is transmitted as soon as the identifier is written in the lin identifier register (linir). at this moment the flag txrdy falls. the break field, the synch field and the identif ier field are sent automatically one after the other. the break field consists of 13 dominant bits a nd 1 recessive bit, the synch field is the charac- ter 0x55 and the identifier corresponds to the character written in the lin identifier register (linir). the identifier parity bits can be automatically computed and sent (see section 25.6.9.8 ). the bit txrdy is set when the identifier character is transferred into the shift register of the transmitter. figure 25-39. header transmission txd baud rate clock start bit write linir 10101010 txrdy stop bit start bit id0 id1 id2 id3 id4 id5 id6 id7 break field 13 dominant bits (at 0) stop bit break delimiter 1 recessive bit (at 1) synch byte = 0x55 linir id
586 32072d?04/2011 at32uc3a3/a4 25.6.9.6 header reception (slave node configuration) all the lin frames start with a header which is sent by the master node and consists of a synch break field, synch field and identifier field. in slave node configuration, the frame handling starts with the reception of the header. the usart uses a break detection threshold of 11 nominal bit times at the actual baud rate. at any time, if 11 consecutive rece ssive bits are detected on the bus, the usart detects a break field. as long as a break field has not been detected, the usart stays idle and the received data are not taken in account. when a break field has been detected, the usar t expects the synch field character to be 0x55. this field is used to update the actual baud rate in order to stay synchronized (see section 25.6.9.7 ). if the received synch character is not 0x55, an inconsistent synch field error is gen- erated (see section 25.6.10 ). after receiving the synch field, the usart expects to receive the identifier field. when the identifier has been received, the flag linid is set to ?1?. at this moment the field idchr in the lin identifier register (linir) is updated with the re ceived character. the identifier parity bits can be automatically computed and checked (see section 25.6.9.8 ). figure 25-40. header reception 25.6.9.7 slave node synchronization the synchronization is done only in slave node configuration. the procedure is based on time measurement between fallin g edges of the synch field. the falling edges are available in dis- tances of 2, 4, 6 and 8 bit times. figure 25-41. synch field the time measurement is made by a 19-bit counter clocked by the sampling clock (see section 25.6.1 ). break field 13 dominant bits (at 0) break delimiter 1 recessive bit (at 1) start bit 10101010 stop bit start bit id0 id1 id2 id4 id3 id6 id5 id7 stop bit synch byte = 0x55 baud rate clock rxd write us_cr with rststa=1 us_linir linid start bit stop bit synch field 8 tbit 2 tbit 2 tbit 2 tbit 2 tbit
587 32072d?04/2011 at32uc3a3/a4 when the start bit of the synch field is detected the counter is reset. then during the next 8 tbits of the synch field, the counter is increm ented. at the end of these 8 tbits, the counter is stopped. at this moment, the 16 most significant bi ts of the counter (value divided by 8) gives the new clock divider (cd) and the 3 least significant bits of this value (the remainder) gives the new fractional part (fp). when the synch field has been re ceived, the clock divider (cd) and the fractional part (fp) are updated in the baud rate generator register (brgr). figure 25-42. slave node synchronization the accuracy of the synchronization depends on several parameters: ? the nominal clock frequency (f nom ) (the theoretical slave node clock frequency) ? the baudrate ? the oversampling (over=0 => 16x or over=0 => 8x) the following formula is used to compute the deviation of the slave bit rate relative to the master bit rate after synchronization (f slave is the real slave node clock frequency). f tol_unsynch is the deviation of the real slave node clock from the nominal clock frequency. the lin standard imposes that it must not exceed 15%. the lin standard imposes also that for communication between two nodes, their bit rate must not differ by more than 2%. this means that the baudrate_deviation must not exceed 1%. it follows from that, a minimum value for the nominal clock frequency: rxd baud rate clock linidrx synchro counter 000_0011_0001_0110_1101 brgr clcok divider (cd) 0000_0110_0010_1101 brgr fractional part (fp) 101 initial cd initial fp reset start bit 10101010 stop bit start bit id0 id1 id2 id3 id4 id5 id6 id7 break field 13 dominant bits (at 0) stop bit break delimiter 1 recessive bit (at 1) synch byte = 0x55 baudrate_deviation 100 [ 82over ? () + ] baudrate 8f slave -------------------------------------------------------------------------------------------- - ?? ?? % = baudrate_deviation 100 [ 82over ? () + ] baudrate 8 f tol_unsynch 100 --------------------------------------- ?? ?? xf nom -------------------------------------------------------------------------------------------- - ?? ?? ?? ?? ?? % = 0,5 ? +0,5 -1 +1 << ?
588 32072d?04/2011 at32uc3a3/a4 examples: ? baudrate = 20 kbit/s, over=0 (oversampling 16x) => f nom (min) = 2.64 mhz ? baudrate = 20 kbit/s, over=1 (oversampling 8x) => f nom (min) = 1.47 mhz ? baudrate = 1 kbit/s, over=0 (oversampling 16x) => f nom (min) = 132 khz ? baudrate = 1 kbit/s, over=1 (oversampling 8x) => f nom (min) = 74 khz if the fractional baud rate is not used, the accuracy of the synchronization becomes much lower. when the counter is stopped, the 16 most significant bits of the counter (value divided by 8) gives the new clock divider (cd) . this value is rounded by adding th e first insignificant bit. the equation of the baudrate deviation is the same as given above, but the constants are as follows: it follows from that, a minimum value for the nominal clock frequency: examples: ? baudrate = 20 kbit/s, over=0 (oversampling 16x) => f nom (min) = 19.12 mhz ? baudrate = 20 kbit/s, over=1 (oversampling 8x) => f nom (min) = 9.71 mhz ? baudrate = 1 kbit/s, over=0 (oversampling 16x) => f nom (min) = 956 khz ? baudrate = 1 kbit/s, over=1 (oversampling 8x) => f nom (min) = 485 khz 25.6.9.8 identifier parity a protected identifier consists of two sub-fields; the identifier and the identifier parity. bits 0 to 5 are assigned to the identifier and bits 6 and 7 are assigned to the parity. the usart interface can generate/check these parity bits, but this feature can also be disabled. the user can choose between two modes by the pardis bit of the lin mode register (linmr): ? pardis = 0: during header transmission, the parity bits are computed and sent with the 6 least significant bits of the idchr field of the lin identifier register (linir). the bits 6 and 7 of this register are discarded. during header reception, the parity bits of the identifier are checked. if the parity bits are wrong, an identifier parity error occurs (see section 25.6.3.8 ). only the 6 least significant bits of the idchr field are updated with the received iden tifier. the bits 6 and 7 are stuck at 0. ? pardis = 1: during header transmission, all th e bits of the idchr field of the lin identifier register (linir) are sent on the bus. during header reception, all the bits of the idchr field are updated with the received identifier. f nom min () 100 0,5 8 2 over ? () 1 + [] baudrate 8 15 ? 100 --------- - 1 + ?? ?? 1% ------------------------------------------------------------------------------------------------ ?? ?? ?? ?? ?? hz = 4 ? +4 -1 +1 << ? ? () 1 + [] baudrate 8 15 ? 100 --------- - 1 + ?? ?? 1% ------------------------------------------------------------------------------------------- ?? ?? ?? ?? ?? hz =
589 32072d?04/2011 at32uc3a3/a4 25.6.9.9 node action in function of the identifier, the node is concerned, or not, by the lin response. consequently, after sending or receiving the identifier, the us art must be configured. there are three possi- ble configurations: ? publish: the node sends the response. ? subscribe: the node receives the response. ? ignore: the node is not concerned by the response, it does not send and does not receive the response. this configuration is made by the field, node action (nact), in the linmr register (see section 25.7.16 ). example: a lin cluster that contains a master and two slaves: ? data transfer from the master to the slave 1 and to the slave 2: nact(master)=publish nact(slave1)=subscribe nact(slave2)=subscribe ? data transfer from the master to the slave 1 only: nact(master)=publish nact(slave1)=subscribe nact(slave2)=ignore ? data transfer from the slave 1 to the master: nact(master)=subscribe nact(slave1)=publish nact(slave2)=ignore ? data transfer from the slave1 to the slave2: nact(master)=ignore nact(slave1)=publish nact(slave2)=subscribe ? data transfer from the slave2 to the master and to the slave1: nact(master)=subscribe nact(slave1)=subscribe nact(slave2)=publish
590 32072d?04/2011 at32uc3a3/a4 25.6.9.10 response data length the lin response data length is the number of data fields (bytes) of the response excluding the checksum. the response data length can either be configur ed by the user or be defined automatically by bits 4 and 5 of the identifier (compatibility to lin specification 1.1). the user can choose between these two modes by the dlm bit of the lin mode register (linmr): ? dlm = 0: the response data length is configured by the user via the dlc field of the lin mode register (linmr). the response data length is equal to (dlc + 1) bytes. dlc can be programmed from 0 to 255, so the response can contain from 1 data byte up to 256 data bytes. ? dlm = 1: the response data length is defined by the identifier (idchr in linir) according to the table below. the dlc field of the lin mode register (linmr) is discarded. the response can contain 2 or 4 or 8 data bytes. figure 25-43. response data length table 25-14. response data length if dlm = 1 idchr[5] idchr[4] response data length [bytes] 00 2 01 2 10 4 11 8 user configuration: 1 - 256 data fields (dlc+1) identifier configuration: 2/4/8 data fields sync break sync field identifier field checksum field data field data field data field data field
591 32072d?04/2011 at32uc3a3/a4 25.6.9.11 checksum the last field of a frame is the checksum. the checksum contains the inverted 8- bit sum with carry, over all data bytes or all data bytes and the protected identifier. checksum calculation over the data bytes only is called classic checks um and it is used for communication with lin 1.3 slaves. checksum calculation over the data by tes and the protected identifier byte is called enhanced checksum and it is used for communication with lin 2.0 slaves. the usart can be configured to: ? send/check an enhanced checksum automatically (chkdis = 0 & chktyp = 0) ? send/check a classic checksum automatically (chkdis = 0 & chktyp = 1) ? not send/check a checksum (chkdis = 1) this configuration is made by the checksum type (chktyp) and ch ecksum disable (chkdis) fields of the lin mode register (linmr). if the checksum feature is disabled, the user can send it manually all the same, by considering the checksum as a normal data byte and by adding 1 to the response data length (see section 25.6.9.10 ).
592 32072d?04/2011 at32uc3a3/a4 25.6.9.12 frame slot mode this mode is useful only for master nodes. it respects the following rule: each frame slot shall be longer than or equal to tframe_maximum. if the frame slot mode is enabled (fsdis = 0) and a frame transfer has been completed, the txrdy flag is set again only after tframe_maximum delay, from the start of frame. so the mas- ter node cannot send a new header if the frame slot duration of the previous frame is inferior to tframe_maximum. if the frame slot mode is disabled (fsdis = 1) and a frame transfer has been completed, the txrdy flag is set again immediately. the tframe_maximum is calculated as below: if the checksum is sent (chkdis = 0): ? theader_nominal = 34 x tbit ? tresponse_nominal = 10 x (ndata + 1) x tbit ? tframe_maximum = 1.4 x (theader_nominal + tresponse_nominal + 1) (note:) ? tframe_maximum = 1.4 x (34 + 10 x (dlc + 1 + 1) + 1) x tbit ? tframe_maximum = (77 + 14 x dlc) x tbit if the checksum is not sent (chkdis = 1): ? theader_nominal = 34 x tbit ? tresponse_nominal = 10 x ndata x tbit ? tframe_maximum = 1.4 x (theader_nominal + tresponse_nominal + 1 (note:) ) ? tframe_maximum = 1.4 x (34 + 10 x (dlc + 1) + 1) x tbit ? tframe_maximum = (63 + 14 x dlc) x tbit note: the term ?+1? leads to an integer re sult for tframe_max (lin specification 1.3) figure 25-44. frame slot mode break synch protected identifier data n checksum header inter- frame space response space frame frame slot = tframe_maximum response txrdy write thr write linid data 1 data 2 data 3 data3 data n-1 data n frame slot mode disabled frame slot mode enabled lintc data 1
593 32072d?04/2011 at32uc3a3/a4 25.6.10 lin errors 25.6.10.1 bit error this error is generated when the usart is transmitting and if the transmitted value on the tx line is different from the value sampled on the rx line. if a bit error is detected, the transmission is aborted at the next byte border. this error is reported by linbe in the channel status register (csr). 25.6.10.2 inconsistent synch field error this error is generated in slave node configurati on if the synch field character received is other than 0x55. this error is reported by csr.linisfe 25.6.10.3 identifier parity error this error is generated if the parity of the identi fier is wrong. this error can be generated only if the parity feature is enabled (pardis = 0). this error is reported by csr.linipe 25.6.10.4 checksum error this error is generated if the received checksum is wrong. this error can be generated only if the checksum feature is enabled (chkdis = 0). this error is reported by csr.lince 25.6.10.5 slave not responding error this error is generated when the usart expects a response from another node (nact = sub- scribe) but no valid message appears on the bus within the time frame given by the maximum length of the message frame, tframe_maximum (see section 25.6.9.12 ). this error is disabled if the usart does not expect any message (nact = publish or nact = ignore). this error is reported by csr.linsnre
594 32072d?04/2011 at32uc3a3/a4 25.6.11 lin frame handling 25.6.11.1 master node configuration ? write txen and rxen in cr to enable both the transmitter and the receiver. ? write mode in mr to select the lin mode and the master node configuration. ? write cd and fp in brgr to configure the baud rate. ? write nact, pardis, chkdis, chktype, dlcm , fsdis and dlc in linmr to configure the frame transfer. ? check that txrdy in csr is set to ?1? ? write idchr in linir to send the header what comes next depends on the nact configuration: ? case 1: nact = publish, the usart sends the response ? wait until txrdy in csr rises ? write tchr in thr to send a byte ? if all the data have not been written, redo the two previous steps ? wait until lintc in csr rises ? check the lin errors ? case 2: nact = subscribe, the usart receives the response ? wait until rxrdy in csr rises ? read rchr in rhr ? if all the data have not been read, redo the two previous steps ? wait until lintc in csr rises ? check the lin errors ? case 3: nact = ignore, the usart is not concerned by the response ? wait until lintc in csr rises ? check the lin errors
595 32072d?04/2011 at32uc3a3/a4 figure 25-45. master node configuration, nact = publish figure 25-46. master node configur ation, nact=subscribe frame break synch protected identifier data 1 data n checksum txrdy write thr write linir data 1 data 2 data 3 data n-1 data n rxrdy header inter- frame space response space frame slot = tframe_maximum response data3 lintc fsdis=1 fsdis=0 break synch protected identifier data 1 data n checksum txrdy read rhr write linir data 1 data n-1 data n-1 rxrdy data n data n-2 header inter- frame space response space frame frame slot = tframe_maximum response data3 lintc fsdis=0 fsdis=1
596 32072d?04/2011 at32uc3a3/a4 figure 25-47. master node configuration, nact=ignore 25.6.11.2 slave node configuration ? write txen and rxen in cr to enable both the transmitter and the receiver. ? write mode in mr to select the lin mode and the slave node configuration. ? write cd and fp in brgr to configure the baud rate. ? wait until linid in csr rises ? check linisfe and linpe errors ? read idchr in rhr ? write nact, pardis, chkdis, chktype, dlcm and dlc in linmr to configure the frame transfer. important : if the nact configuration for this frame is publish, the us_linmr register, must be write with nact=publish even if this fiel d is already correctly configured, that in order to set the txready flag and the corresponding peripheral dma controller write transfer request. what comes next depends on the nact configuration: ? case 1: nact = publish, the usart sends the response ? wait until txrdy in csr rises ? write tchr in thr to send a byte ? if all the data have not been written, redo the two previous steps ? wait until lintc in csr rises ? check the lin errors ? case 2: nact = subscribe, the usart receives the response ? wait until rxrdy in csr rises ? read rchr in rhr ? if all the data have not been read, redo the two previous steps ? wait until lintc in csr rises ? check the lin errors txrdy write linir rxrdy lintc break synch protected identifier data 1 data n checksum data n-1 header inter- frame space response space frame frame slot = tframe_maximum response data3 fsdis=1 fsdis=0
597 32072d?04/2011 at32uc3a3/a4 ? case 3: nact = ignore, the usart is not concerned by the response ? wait until lintc in csr rises ? check the lin errors figure 25-48. slave node configuration, nact = publish figure 25-49. slave node configuration, nact = subscribe figure 25-50. slave node configurat ion, nact = ignore break synch protected identifier data 1 data n checksum txrdy write thr read linid data 1 data 3 data n-1 data n rxrdy linidrx data 2 lintc txrdy read rhr read linid rxrdy linidrx lintc break synch protected identifier data 1 data n checksum data 1 data n-1 data n-1 data n data n-2 t xrdy read rhr read linid r xrdy l inidrx l intc break synch protected identifier data 1 data n checksum data n-1
598 32072d?04/2011 at32uc3a3/a4 25.6.12 lin frame handling with the peripheral dma controller the usart can be used in association with the pe ripheral dma controller in order to transfer data directly into/from the on- and off-chip memories without any processor intervention. the peripheral dma controller uses the trigger flags, txrdy and rxrdy, to write or read into the usart. the peripheral dma controller always writes in the transmit holding register (thr) and it always reads in the receive holding register (rhr). the size of the data written or read by the peripheral dma controller in the usart is always a byte. 25.6.12.1 master node configuration the user can choose between two peripheral dma controller modes by the pdcm bit in the lin mode register (linmr): ? pdcm = 1: the lin configuration is stored in the write buffer and it is written by the peripheral dma controller in the transmit holding register thr (instead of the lin mode register linmr). because the peripheral dma controller transfer size is limited to a byte, the transfer is split into two accesses. during the first access the bits, nact, pardis, chkdis, chktyp, dlm and fsdis are written. during the second access the 8-bit dlc field is written. ? pdcm = 0: the lin configuration is not stored in the write buffer and it must be written by the user in the lin mode register (linmr). the write buffer also contains the identifier and the data, if the usart sends the response (nact = publish). the read buffer contains the data if the usart receives the response (nact = subscribe). figure 25-51. master node with periphera l dma controller (pdcm=1) | | | | | | | | nact pardis chkdis chktyp dlm fsdis dlc identifier data 0 data n write buffer rxrdy peripheral bus dlc identifier data 0 data n write buffer rxrdy read buffer node action = publish node action = subscribe peripheral dma controller peripheral dma controller usart lin controller nact pardis chkdis chktyp dlm fsdis usart lin controller txrdy peripheral bus
599 32072d?04/2011 at32uc3a3/a4 figure 25-52. master node with periphera l dma controller (pdcm=0) 25.6.12.2 slave node configuration in this configuration, the peripheral dma cont roller transfers only the data. the identifier must be read by the user in the lin identifier register (linir). the lin mode must be written by the user in the lin mode register (linmr). the write buffer contains the data if the usart sends the response (nact=publish). the read buffer contains the data if the usart receives the response (nact=subscribe). important: if the nact configuration for a fr ame is publish, the us_linmr register, must be write with nact=publish even if this field is already correctly configured, that in order to set the txready flag and the corresponding peripheral dma controller write transfer request. figure 25-53. slave node with peripheral dma controller | | | | rxrdy txrdy peripheral bus usart lin controller data 0 data n | | | | read buffer node action = publish node action = subscribe peripheral dma controller rxrdy peripheral bus data 0 data 1 data n write buffer peripheral dma controller usart lin controller | | | | | | | | data 0 data n rxrdy per ipheral bus read buffer nact = subscribe data 0 data n txrdy per ipheral bus write buffer usart lin controller usart lin controller peripheral dma controller peripheral dma controller
600 32072d?04/2011 at32uc3a3/a4 25.6.13 wake-up request any node in a sleeping lin cluster may request a wake-up. in the lin 2.0 specification, the wakeup reques t is issued by forcing the bus to the dominant state from 250 s to 5 ms. for this, it is necessa ry to send the character 0xf0 in order to impose 5 successive dominant bits. whatever the baud rate is, this character respects the specified timings. ? baud rate min = 1 kbit/s -> tbit = 1ms -> 5 tbits = 5 ms ? baud rate max = 20 kbit/s -> tbi t= 50 s -> 5 tbits = 250 s in the lin 1.3 specification, the wakeup request should be generated with the character 0x80 in order to impose 8 successive dominant bits. the user can choose by the wkuptyp bit in the lin mode register (linmr) either to send a lin 2.0 wakeup request (wkuptyp=0) or to send a lin 1.3 wakeup request (wkuptyp=1). a wake-up request is transmitted by writing the c ontrol register (cr) with the linwkup bit at 1. once the transfer is completed, the lintc flag is asserted in the status register (sr). it is cleared by writing the control register (cr) with the rststa bit at 1.
601 32072d?04/2011 at32uc3a3/a4 25.6.14 bus idle time-out if the lin bus is inactive for a certain duration, the slave nodes shall automatically enter in sleep mode. in the lin 2.0 specification, this time-out is fixed at 4 seconds. in the lin 1.3 specifica- tion, it is fixed at 25000 tbits. in slave node configuration, the receiver time -out detects an idle condition on the rxd line. when a time-out is detected, the bit timeout in the channel status register (csr) rises and can generate an interrupt, thus indicating to the driver to go into sleep mode. the time-out delay period (during which the receiver waits for a new character) is programmed in the to field of the receiver time-out register (rtor). if the to field is programmed at 0, the receiver time-out is disabled and no time-out is detected. the timeou t bit in csr remains at 0. otherwise, the receiver loads a 17-bit counter with the value programmed in to. this counter is decremented at each bit period and reloaded ea ch time a new character is received. if the counter reaches 0, the timeout bit in the status register rises. if sttto is performed, the counter clock is stopped until a first character is received. if retto is performed, the counter starts counting down immediately from the value to. table 25-15. receiver time-out programming lin specification baud rate time-out period to 2.0 1 000 bit/s 4s 4 000 2 400 bit/s 9 600 9 600 bit/s 38 400 19 200 bit/s 76 800 20 000 bit/s 80 000 1.3 - 25 000 tbits 25 000
602 32072d?04/2011 at32uc3a3/a4 25.6.15 test modes the usart can be programmed to operate in three different test modes. the internal loopback capability allows on-boar d diagnostics. in the loopback mode the usart interface pins are dis- connected or not and reconfigured for loopback internally or externally. 25.6.15.1 normal mode normal mode connects the rxd pin on the receiver input and the transmitter output on the txd pin. figure 25-54. normal mode configuration 25.6.15.2 automatic echo mode automatic echo mode allows bit-by-bit retransmission. when a bit is received on the rxd pin, it is sent to the txd pin, as shown in figure 25-55 . programming the transmitter has no effect on the txd pin. the rxd pin is still connected to the receiver input, thus the receiver remains active. figure 25-55. automatic echo mode configuration 25.6.15.3 local loopback mode local loopback mode c onnects the output of the transmitter directly to the input of the receiver, as shown in figure 25-56 . the txd and rxd pins are not used. the rxd pin has no effect on the receiver and the txd pin is continuously driven high, as in idle state. figure 25-56. local loopback mode configuration receiver transmitter rxd txd receiver transmitter rxd txd receiver transmitter rxd txd 1
603 32072d?04/2011 at32uc3a3/a4 25.6.15.4 remote loopback mode remote loopback mode directly connects the rxd pin to the txd pin, as shown in figure 25-57 . the transmitter and the receiver are disabled an d have no effect. this mode allows bit-by-bit retransmission. figure 25-57. remote loopback mode configuration receiver transmitter rxd txd 1
604 32072d?04/2011 at32uc3a3/a4 25.6.16 write protection registers to prevent any single software error that may corrupt usart behavior, certain address spaces can be write-protected by setting the wpen bit in the usart write protect mode register (wpmr). if a write access to the protect ed registers is detect ed, then the wpvs flag in the usart write protect status register (wpsr) is set and the field wpvsrc indicates in which register the write access has been attempted. the wpvs flag is reset by writing the usart wr ite protect mode register (wpmr) with the appropriate access key, wpkey. the protected registers are: ? ?mode register? on page 608 ? ?baud rate generator register? on page 620 ? ?receiver time-out register? on page 621 ? ?transmitter timeguard register? on page 622 ? ?fi di ratio register? on page 623 ? ?irda filter register? on page 625 ? ?manchester configuration register? on page 626
605 32072d?04/2011 at32uc3a3/a4 25.7 user interface note: 1. values in the version register vary wi th the version of the ip block implementation. table 25-16. usart register memory map offset register name access reset 0x0000 control register cr write-only ? 0x0004 mode register mr read-write 0x00000000 0x0008 interrupt enable register ier write-only ? 0x000c interrupt disable register idr write-only ? 0x0010 interrupt mask register imr read-only 0x00000000 0x0014 channel status register csr read-only 0x00000000 0x0018 receiver holding register rhr read-only 0x00000000 0x001c transmitter holding register thr write-only ? 0x0020 baud rate generator register brgr read-write 0x00000000 0x0024 receiver time-out register rtor read-write 0x00000000 0x0028 transmitter timeguard register ttgr read-write 0x00000000 0x0040 fi di ratio register fidi read-write 0x00000174 0x0044 number of errors re gister ner read-only 0x00000000 0x004c irda filter regi ster ifr read-write 0x00000000 0x0050 manchester encoder decoder register man read-write 0x30011004 0x0054 lin mode register linmr read-write 0x00000000 0x0058 lin identifier register linir read-write 0x00000000 0x00e4 write protect mode register wpmr read-write 0x00000000 0x00e8 write protect status register wpsr read-only 0x00000000 0x00fc version register version read-only 0x? (1)
606 32072d?04/2011 at32uc3a3/a4 25.7.1 control register name: cr access type: write-only offset: 0x0 reset value: - ? linwkup: send lin wakeup signal 0: no effect: 1: sends a wakeup signal on the lin bus. ? linabt: abort lin transmission 0: no effect. 1: abort the current lin transmission. ? rtsdis/rcs: request to send disable/release spi chip select if usart does not operate in spi master mode (mode 0xe): 0: no effect. 1: drives the pin rts to 1. if usart operates in spi master mode (mode = 0xe): rcs = 0: no effect. rcs = 1: releases the slave select line nss (rts pin). ? rtsen/fcs: request to send enable/force spi chip select if usart does not operate in spi master mode (mode 0xe): 0: no effect. 1: drives the pin rts to 0. if usart operates in spi master mode (mode = 0xe): fcs = 0: no effect. fcs = 1: forces the slave select line nss (rts pin) to 0, ev en if usart is no transmitting, in order to address spi slave devices supporting the csaat mode (chip select active after transfer). ? dtrdis: data terminal ready disable 0: no effect. 1: drives the pin dtr to 1. ? dtren: data terminal ready enable 0: no effect. 1: drives the pin dtr at 0. ? retto: rearm time-out 0: no effect 1: restart time-out 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? linwkup linabt rtsdis/ rcs rtsen/fcs dtrdis dtren 15 14 13 12 11 10 9 8 retto rstnack rstit senda sttto stpbrk sttbrk rststa 76543210 txdis txen rxdis rxen rsttx rstrx ? ?
607 32072d?04/2011 at32uc3a3/a4 ? rstnack: reset non acknowledge 0: no effect 1: resets nack in csr. ? rstit: reset iterations 0: no effect. 1: resets iteration in csr. no ef fect if the iso7816 is not enabled. ? senda: send address 0: no effect. 1: in multidrop mode only, the next character writ ten to the thr is sent with the address bit set. ? sttto: start time-out 0: no effect. 1: starts waiting for a character before clocking the ti me-out counter. resets the status bit timeout in csr. ? stpbrk: stop break 0: no effect. 1: stops transmission of the break after a minimum of one characte r length and transmits a high level during 12-bit periods. no effect if no break is being transmitted. ? sttbrk: start break 0: no effect. 1: starts transmission of a break after the characters present in thr and the tr ansmit shift register have been transmitted. no effect if a break is already being transmitted. ? rststa: reset status bits 0: no effect. 1: resets the status bits pare, frame, ovre, manerr, linbe, linsfe, linipe, lince, linsnre and rxbrk in csr. ? txdis: transmitter disable 0: no effect. 1: disables the transmitter. ? txen: transmitter enable 0: no effect. 1: enables the transmitter if txdis is 0. ? rxdis: receiver disable 0: no effect. 1: disables the receiver. ? rxen: receiver enable 0: no effect. 1: enables the receiver, if rxdis is 0. ? rsttx: reset transmitter 0: no effect. 1: resets the transmitter. ? rstrx: reset receiver 0: no effect. 1: resets the receiver.
608 32072d?04/2011 at32uc3a3/a4 25.7.2 mode register name: mr access type: read-write offset: 0x4 reset value: - this register can only be written if the wpen bit is cleared in the write protect mode register (if exists). ? onebit: start frame delimiter selector 0: start frame delimiter is command or data sync. 1: start frame delimiter is one bit. ? modsync: manc hester synchronization mode 0:the manchester start bit is a 0 to 1 transition 1: the manchester start bit is a 1 to 0 transition. ? man: manchester encoder/decoder enable 0: manchester encoder/decoder are disabled. 1: manchester encoder/decoder are enabled. ? filter: infrared receive line filter 0: the usart does not filter the receive line. 1: the usart filters the receive line using a three-sa mple filter (1/16-bit clock) (2 over 3 majority). ? max_iteration defines the maximum number of iterations in mode iso7816, protocol t= 0. ? var_sync: variable synchronization of co mmand/data sync start frame delimiter 0: user defined configuration of comma nd or data sync field depending on sync value. 1: the sync field is updated when a char acter is written into thr register. ? dsnack: disable successive nack 0: nack is sent on the iso line as soon as a parity error occurs in the received character (unless inack is set). 1: successive parity errors are counted up to the value specifi ed in the max_iteration field. these parity errors generate a nack on the iso line. as soon as this value is reached, no addi tional nack is sent on the iso line. the flag iteration is asserted. ? inack: inhibit non acknowledge 0: the nack is generated. 1: the nack is not generated. ? over: oversampling mode 0: 16x oversampling. 1: 8x oversampling. 31 30 29 28 27 26 25 24 onebit modsync man filter ? max_iteration 23 22 21 20 19 18 17 16 ? var_sync dsnack inack over clko mode9 msbf/cpol 15 14 13 12 11 10 9 8 chmode nbstop par sync/cpha 76543210 chrl usclks mode
609 32072d?04/2011 at32uc3a3/a4 ? clko: clock output select 0: the usart does not drive the clk pin. 1: the usart drives the clk pin if usclks does not select the external clock clk. ? mode9: 9-bit character length 0: chrl defines character length. 1: 9-bit character length. ? msbf/cpol: bit order or spi clock polarity if usart does not operate in spi mode (mode 0xe and 0xf): msbf = 0: least significant bit is sent/received first. msbf = 1: most significant bit is sent/received first. if usart operates in spi mode (slave or master, mode = 0xe or 0xf): cpol = 0: the inactive state value of spck is logic level zero. cpol = 1: the inactive state va lue of spck is logic level one. cpol is used to determine the inactive state value of the seri al clock (spck). it is used with cpha to produce the required clock/data relationship between master and slave devices. ? chmode: channel mode ? nbstop: number of stop bits ? par: parity type table 25-17. chmode mode description 0 0 normal mode 0 1 automatic echo. receiver input is connected to the txd pin. 1 0 local loopback. transmitter output is connected to the receiver input. 1 1 remote loopback. rxd pin is internally connected to the txd pin. table 25-18. nbstop asynchronous (sync = 0) synchronous (sync = 1) 0 0 1 stop bit 1 stop bit 0 1 1.5 stop bits reserved 1 0 2 stop bits 2 stop bits 1 1 reserved reserved table 25-19. par parity type 0 0 0 even parity 001odd parity 0 1 0 parity forced to 0 (space) 0 1 1 parity forced to 1 (mark) 1 0 x no parity 1 1 x multidrop mode
610 32072d?04/2011 at32uc3a3/a4 ? sync/cpha: synchronous mode select or spi clock phase if usart does not operate in spi mode (mode is 0xe and 0xf): sync = 0: usart operates in asynchronous mode. sync = 1: usart operates in synchronous mode. if usart operates in spi mode (mode = 0xe or 0xf): cpha = 0: data is changed on the leading edge of spck and captured on the following edge of spck. cpha = 1: data is captured on the leading edge of spck and changed on the following edge of spck. cpha determines which edge of spck causes data to change an d which edge causes data to be captured. cpha is used with cpol to produce the required clock/data rela tionship between master and slave devices. ? chrl: character length. ? usclks: clock selection note: 1. the value of div is device dependent. please re fer to the module confi guration section at the end of this chapter. ? mode table 25-20. chrl character length 0 0 5 bits 0 1 6 bits 1 0 7 bits 1 1 8 bits table 25-21. usclks selected clock 0 0 clk_usart 0 1 clk_usart/div (1) 10reserved 11 clk table 25-22. mode mode of the usart 0000normal 0001rs485 0 0 1 0 hardware handshaking 0011modem 0 1 0 0 is07816 protocol: t = 0 0 1 1 0 is07816 protocol: t = 1 1000irda 1 0 1 0 lin master 1011lin slave
611 32072d?04/2011 at32uc3a3/a4 1110spi master 1 1 1 1 spi slave others reserved table 25-22. mode mode of the usart
612 32072d?04/2011 at32uc3a3/a4 25.7.3 interrupt enable register name: ier access type: write-only offset: 0x8 reset value: - writing a zero to a bit in this register has no effect. writing a one to a bit in this register will set the corresponding bit in imr. for backward compatibility the mane bit has been duplicated to the manea bit position . writing either o ne or the other has the same effect. 31 30 29 28 27 26 25 24 ? ? linsnre lince linipe linisfe linbe manea 23 22 21 20 19 18 17 16 ? ? ? mane ctsic dcdic dsric riic 15 14 13 12 11 10 9 8 lintc linid nack/linbk rxbuff ? iter/unre txempty timeout 76543210 pare frame ovre ? ? rxbrk txrdy rxrdy
613 32072d?04/2011 at32uc3a3/a4 25.7.4 interrupt disable register name: idr access type: write-only offset: 0xc reset value: - writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in imr. for backward compatibility the mane bit has been duplicated to the manea bit position . writing either o ne or the other has the same effect. 31 30 29 28 27 26 25 24 ? ? linsnre lince linipe linisfe linbe manea 23 22 21 20 19 18 17 16 ? ? ? mane ctsic dcdic dsric riic 15 14 13 12 11 10 9 8 lintc linid nack/linbk rxbuff ? iter/unre txempty timeout 76543210 pare frame ovre ? ? rxbrk txrdy rxrdy
614 32072d?04/2011 at32uc3a3/a4 25.7.5 interrupt mask register name: imr access type: read-only offset: 0x10 reset value: - 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. a bit in this register is cleared when the corresponding bit in idr is written to one. a bit in this register is set when the corresponding bit in ier is written to one. for backward compatibility the mane bit has been duplicated to the manea bit position. r eading either one or the other has the same effect. 31 30 29 28 27 26 25 24 ? ? linsnre lince linipe linisfe linbe manea 23 22 21 20 19 18 17 16 ? ? ? mane ctsic dcdic dsric riic 15 14 13 12 11 10 9 8 lintc linid nack/linbk rxbuff ? iter/unre txempty timeout 76543210 pare frame ovre ? ? rxbrk txrdy rxrdy
615 32072d?04/2011 at32uc3a3/a4 25.7.6 channel status register name: csr access type: read-only offset: 0x14 reset value: - ? linsnre: lin slave not responding error 0: no lin slave not responding error has been detected since the last rststa. 1: a lin slave not responding error has been detected since the last rststa. ? lince: lin checksum error 0: no lin checksum error has been detected since the last rststa. 1: a lin checksum error has been detected since the last rststa. ? linipe: lin identifi er parity error 0: no lin identifier parity error has been detected since the last rststa. 1: a lin identifier parity error has been detected since the last rststa. ? linisfe: lin inconsistent synch field error 0: no lin inconsistent synch field erro r has been detected since the last rststa 1: the usart is configured as a slave node and a lin incons istent synch field error has been detected since the last rststa. ? linbe: lin bit error 0: no bit error has been detected since the last rststa. 1: a bit error has been detected since the last rststa. ? manerr: manchester error 0: no manchester error has been detected since the last rststa. 1: at least one manchester error has been detected since the last rststa. ? cts: image of cts input 0: cts is at 0. 1: cts is at 1. ? dcd: image of dcd input 0: dcd is at 0. 1: dcd is at 1. ? dsr: image of dsr input 0: dsr is at 0 1: dsr is at 1. 31 30 29 28 27 26 25 24 ? ? linsnre lince linipe linisfe linbe manerr 23 22 21 20 19 18 17 16 cts dcd dsr ri ctsic dcdic dsric riic 15 14 13 12 11 10 9 8 lintc linid nack/linbk rxbuff ? iter/unre txempty timeout 76543210 pare frame ovre ? ? rxbrk txrdy rxrdy
616 32072d?04/2011 at32uc3a3/a4 ? ri: image of ri input 0: ri is at 0. 1: ri is at 1. ? ctsic: clear to send input change flag 0: no input change has been detected on th e cts pin since the last read of csr. 1: at least one input change has been detect ed on the cts pin since the last read of csr. ? dcdic: data carrier detect input change flag 0: no input change has been detected on the dcd pin since the last read of csr. 1: at least one input change has been detect ed on the dcd pin since the last read of csr. ? dsric: data set read y input change flag 0: no input change has been detected on the dsr pin since the last read of csr. 1: at least one input change has been detected on the dsr pin since the last read of csr. ? riic: ring indicator input change flag 0: no input change has been detected on th e ri pin since the last read of csr. 1: at least one input change has been detect ed on the ri pin since the last read of csr. ? lintc: lin transfer completed 0: the usart is idle or a lin transfer is ongoing. 1: a lin transfer has been comp leted since the last rststa. ? linid: lin identifier 0: no lin identifier received or sent 1: the usart is configured as a slave node and a lin identifier has been received or the usart is configured as a master node and a lin identifier has been sent since the last rststa. ? nack: non acknowledge 0: no non acknowledge has not been detected since the last rstnack. 1: at least one non acknowledge has been detected since the last rstnack. ? rxbuff: reception buffer full 0: the signal buffer full from the receive peripheral dma controller channel is inactive. 1: the signal buffer full from the receive peripheral dma controller channel is active. ? iter/unre: max number of repetitions reached or spi underrun error if usart does not operate in spi slave mode (mode 0xf): iter = 0: maximum number of repetitions has not been reached since the last rststa. iter = 1: maximum number of repetitions has been reached since the last rststa. if usart operates in spi slave mode (mode = 0xf): unre = 0: no spi underrun error has occurred since the last rststa. unre = 1: at least one spi underrun error has occurred since the last rststa. ? txempty: transmitter empty 0: there are characters in either thr or the tran smit shift register, or the transmitter is disabled. 1: there are no characters in thr, nor in the transmit shift register. ? timeout: receiver time-out 0: there has not been a time-out since the last start time-o ut command (sttto in cr) or the time-out register is 0. 1: there has been a time-out since the last start time-out command (sttto in cr). ? pare: parity error 0: no parity error has been det ected since the last rststa. 1: at least one parity error has been detected since the last rststa. ? frame: framing error 0: no stop bit has been detected low since the last rststa. 1: at least one stop bit has been det ected low since the last rststa. ? ovre: overrun error 0: no overrun error has occurred since the last rststa. 1: at least one overrun error has occurred since the last rststa.
617 32072d?04/2011 at32uc3a3/a4 ? rxbrk: break received/end of break 0: no break received or end of break detected since the last rststa. 1: break received or end of brea k detected since the last rststa. ? txrdy: transmitter ready 0: a character is in the thr waiting to be transferred to the transmit shift register, or an sttbrk command has been requested, or the transmitter is disabled. as so on as the transmitter is enabled, txrdy becomes 1. 1: there is no character in the thr. ? rxrdy: receiver ready 0: no complete character has been received since the last read of rhr or the receiver is disabled. if characters were being received when the receiver was disabled, rxrdy changes to 1 when the receiver is enabled. 1: at least one complete character has been received and rhr has not yet been read.
618 32072d?04/2011 at32uc3a3/a4 25.7.7 receive holding register name: rhr access type: read-only offset: 0x18 reset value: 0x00000000 ? rxsynh: received sync 0: last character received is a data. 1: last character received is a command. ? rxchr: received character last character received if rxrdy is set. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 rxsynh ??????rxchr 76543210 rxchr
619 32072d?04/2011 at32uc3a3/a4 25.7.8 usart transmit holding register name: thr access type: write-only offset: 0x1c reset value: - ? txsynh: sync field to be transmitted 0: the next character sent is encoded as a data. start frame delimiter is data sync. 1: the next character sent is encoded as a co mmand. start frame deli miter is command sync. ? txchr: character to be transmitted next character to be transmitted after the current character if txrdy is not set. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txsynh ??????txchr 76543210 txchr
620 32072d?04/2011 at32uc3a3/a4 25.7.9 baud rate generator register name: brgr access type: read-write offset: 0x20 reset value: 0x00000000 this register can only be written if the wpen bit is cleared in the write protect mode register. ? fp: fractional part 0: fractional divider is disabled. 1 - 7: baudrate resolution, defined by fp x 1/8. ? cd: clock divider 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ????? fp 15 14 13 12 11 10 9 8 cd 76543210 cd table 25-23. cd mode iso7816 mode = iso7816 sync = 0 sync = 1 or mode = spi (master or slave) over = 0 over = 1 0 baud rate clock disabled 1 to 65535 baud rate = selected clock/16/cd baud rate = selected clock/8/cd baud rate = selected clock /cd baud rate = selected clock/cd/fi_di_ratio
621 32072d?04/2011 at32uc3a3/a4 25.7.10 receiver time-out register name: rtor access type: read-write offset: 0x24 reset value: 0x00000000 this register can only be written if the wpen bit is cleared in the write protect mode register. ? to: time-out value 0: the receiver time-out is disabled. 1 - 131071: the receiver time-out is enabled and the time-out delay is to x bit period. note that the size of the to counter can change depending of implementation. see the mo dule configuration section. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????to 15 14 13 12 11 10 9 8 to 76543210 to
622 32072d?04/2011 at32uc3a3/a4 25.7.11 transmitter timeguard register name: ttgr access type: read-write offset: 0x28 reset value: 0x00000000 this register can only be written if the wpen bit is cleared in the write protect mode register. ? tg: timeguard value 0: the transmitter timeguard is disabled. 1 - 255: the transmitter timeguard is enabled and the timeguard delay is tg x bit period. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 tg
623 32072d?04/2011 at32uc3a3/a4 25.7.12 fi di ratio register name: fidi access type: read-write offset: 0x40 reset value: 0x00000174 this register can only be written if the wpen bit is cleared in the write protect mode register. ? fi_di_ratio: fi over di ratio value 0: if iso7816 mode is selected, the baud rate generator generates no signal. 1 - 2047: if iso7816 mode is selected, the baud rate is the clock provided on clk divided by fi_di_ratio. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ????? fi_di_ratio 76543210 fi_di_ratio
624 32072d?04/2011 at32uc3a3/a4 25.7.13 number of errors register name: ner access type: read-only offset: 0x44 reset value: - ? nb_errors: number of errors total number of errors that occurred during an iso7816 tr ansfer. this register automatically clears when read. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 nb_errors
625 32072d?04/2011 at32uc3a3/a4 25.7.14 irda filter register name: ifr access type: read-write offset: 0x4c reset value: 0x00000000 this register can only be written if the wpen bit is cleared in the write protect mode register (if exists). irda_filter: irda filter sets the filter of the irda demodulator. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 irda_filter
626 32072d?04/2011 at32uc3a3/a4 25.7.15 manchester configuration register name: man access type: read-write offset: 0x50 reset value: 0x30011004 this register can only be written if the wpen bit is cleared in the write protect mode register (if exists). ? drift: drift compensation 0: the usart can not recover fr om an important clock drift 1: the usart can recover from clock drift. the 16x clock mode must be enabled. ? rx_mpol: receiver manchester polarity 0: logic zero is coded as a zero-to-one transition, logic one is coded as a one-to-zero transition. 1: logic zero is coded as a one-to-zero transition, logic one is coded as a zero-to-one transition. ? rx_pp: receiver preamble pattern detected ? rx_pl: receiver preamble length 0: the receiver preamble pattern detection is disabled 1 - 15: the detected preamble length is rx_pl x bit period ? tx_mpol: transmitter manchester polarity 0: logic zero is coded as a zero-to-one transition, logic one is coded as a one-to-zero transition. 1: logic zero is coded as a one-to-zero transition, logic one is coded as a zero-to-one transition. 31 30 29 28 27 26 25 24 ? drift 1 rx_mpol ? ? rx_pp 23 22 21 20 19 18 17 16 ???? rx_pl 15 14 13 12 11 10 9 8 ? ? ? tx_mpol ? ? tx_pp 76543210 ???? tx_pl table 25-24. rx_pp preamble pattern de fault polarity assumed (rx_mpol fi eld not set) 0 0 all_one 0 1 all_zero 10zero_one 11one_zero
627 32072d?04/2011 at32uc3a3/a4 ? tx_pp: transmitter preamble pattern ? tx_pl: transmitter preamble length 0: the transmitter preamble pattern generation is disabled 1 - 15: the preamble length is tx_pl x bit period table 25-25. tx_pp preamble pattern default polari ty assumed (tx_mpol field not set) 0 0 all_one 0 1 all_zero 10zero_one 11one_zero
628 32072d?04/2011 at32uc3a3/a4 25.7.16 lin mode register name: linmr access type: read-write offset: 0x54 reset value: 0x00000000 ? pdcm: peripheral dma controller mode 0: the lin mode register linmr is not written by the peripheral dma controller. 1: the lin mode register linmr (excepting that bi t) is written by the peripheral dma controller. ? dlc: data length control 0 - 255: defines the response data length if dlm=0,in th at case the response data length is equal to dlc+1 bytes. ? wkuptyp: wakeup signal type 0: setting the bit linwkup in the contro l register sends a lin 2.0 wakeup signal. 1: setting the bit linwkup in the contro l register sends a lin 1.3 wakeup signal. ? fsdis: frame slot mode disable 0: the frame slot mode is enabled. 1: the frame slot mode is disabled. ? dlm: data length mode 0: the response data length is defined by the field dlc of this register. 1: the response data length is defined by the bi ts 4 and 5 of the ident ifier (idchr in linir). ? chktyp: checksum type 0: lin 2.0 ?enhanced? checksum 1: lin 1.3 ?classic? checksum ? chkdis: checksum disable 0: in master node configuration, the checksum is computed and sent automatically. in slave node configuration, the checksum is checked automatically. 1: whatever the node configuration is, the checks um is not computed/sent and it is not checked. ? pardis: parity disable 0: in master node configuration, the identifier parity is computed and sent automatically. in master node and slave node configuration, the parity is checked automatically. 1:whatever the node configuration is , the identifier parity is not com puted/sent and it is not checked. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????pdcm 15 14 13 12 11 10 9 8 dlc 76543210 wkuptyp fsdis dlm chktyp chkdis pardis nact
629 32072d?04/2011 at32uc3a3/a4 ? nact: lin node action table 1. nact mode description 0 0 publish: the usart transmits the response. 0 1 subscribe: the usart receives the response. 1 0 ignore: the usart does not transmit and does not receive the response. 11reserved
630 32072d?04/2011 at32uc3a3/a4 25.7.17 lin identifier register name: linir access type: read-write or read-only offset: 0x58 reset value: 0x00000000 ? idchr: identifier character if mode=0xa (master node configuration): idchr is read-write and its value is the identifier character to be transmitted. if mode=0xb (slave node configuration): idchr is read-only and its value is the last identifier character that has been received. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 idchr
631 32072d?04/2011 at32uc3a3/a4 25.7.18 write protect mode register register name: wpmr access type: read-write offset: 0xe4 reset value: see table 25-16 ? wpkey: write protect key should be written at value 0x555341 ("usa" in ascii). writing an y other value in this field aborts the write operation of the wpen bit. always reads as 0. ? wpen: write protect enable 0 = disables the write protect if wpkey corre sponds to 0x555341 ("usa" in ascii). 1 = enables the write protect if wpkey corr esponds to 0x555341 ("usa" in ascii). protects the registers: ? ?mode register? on page 608 ? ?baud rate generator register? on page 620 ? ?receiver time-out register? on page 621 ? ?transmitter timeguard register? on page 622 ? ?fi di ratio register? on page 623 ? ?irda filter register? on page 625 ? ?manchester configuration register? on page 626 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ???????wpen
632 32072d?04/2011 at32uc3a3/a4 25.7.19 write protect status register register name: wpsr access type: read-only offset: 0xe8 reset value: see table 25-16 ? wpvsrc: write protect violation source when wpvs is active, this field indicates the write- protected register (through address offs et or code) in which a write access has been attempted. ? wpvs: write protect violation status 0 = no write protect violation has occurred since the last read of the wpsr register. 1 = a write protect violation has occurred si nce the last read of the wpsr register. if this violation is an unauthorized attem pt to write a protected register, the associated violation is reported into field wpvsrc. note: reading wpsr automatically clears all fields. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ???????wpvs
633 32072d?04/2011 at32uc3a3/a4 25.7.20 version register name: version access type: read-only offset: 0xfc reset value: - ? mfn reserved. no functionality associated. ? version version of the module. no functionality associated. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???? mfn 15 14 13 12 11 10 9 8 ???? version 76543210 version
634 32072d?04/2011 at32uc3a3/a4 25.8 module configuration the specific configuration for each usart instance is listed in the following tables.the module bus clocks listed here are connected to the system bus clocks according to the table in the sys- tem bus clock connections section. 25.8.1 clock connections each usart can be connected to an internally divided clock: table 25-26. module configuration feature usart0 usart2 usart3 usart1 spi logic implemented implemented lin logic implemented implemented manchester logic not implemented implemented modem logic not implemented implemented irda logic not implemented implemented rs485 logic not implemented implemented fractional baudrate implemented implemented iso7816 not implemented implemented div value for divided clk_usart 8 8 receiver time-out counter size (size of the rtor.to field) 8-bits 17-bits table 25-27. module clock name module name clock name description usart0 clk_usart0 peripheral bus clock from the pba clock domain usart1 clk_usart1 peripheral bus clock from the pba clock domain usart2 clk_usart2 peripheral bus clock from the pba clock domain usart3 clk_usart3 peripheral bus clock from the pba clock domain table 25-28. usart clock connections usart source name connection 0 internal clk_div pba clock / 8 (clk_pba_usart_div) 1 pba clock / 8 (clk_pba_usart_div) 2 pba clock / 8 (clk_pba_usart_div) 3 pba clock / 8 (clk_pba_usart_div)
635 32072d?04/2011 at32uc3a3/a4 25.8.2 register reset values table 25-29. register reset values register reset value version 0x00000420
636 32072d?04/2011 at32uc3a3/a4 26. hi-speed usb on-the -go interface (usbb) rev: 3.2.0.12 26.1 features ? compatible with the usb 2.0 specification ? supports high (480mbit/s), fu ll (12mbit/s) and low (1.5mbit/s) speed device and embedded host ? eight pipes/endpoints ? 2368bytes of embedded dual-port ram (dpram) for pipes/endpoints ? up to 2 memory banks per pipe/endpoint (not for control pipe/endpoint) ? flexible pipe/endpoint configuration and management with dedicated dma channels ? on-chip utmi transceiver including pull-ups/pull-downs ? on-chip pad including vb us analog comparator 26.2 overview the universal serial bus (usb) mcu device complies with the universal serial bus (usb) 2.0 specification, in all speeds. each pipe/endpoint can be configured in one of several transfer types. it can be associated with one or more banks of a dual-port ram (dpram) used to store the current data payload. if sev- eral banks are used (?ping-pong? mode), then one dpram bank is read or written by the cpu or the dma while the other is read or written by the usbb core. this feature is mandatory for iso- chronous pipes/endpoints. table 26-1 on page 636 describes the hardware configuration of the usb mcu device. the theoretical maximal pipe/endpoint configurat ion (3648bytes) exceeds the real dpram size (2368bytes). the user needs to be aware of this when configuring pipes/endpoints. to fully use the 2368bytes of dpram, the user could for example use the configuration described in table 26-2 on page 636 . table 26-1. description of usb pipes/endpoints pipe/endpoint mnemonic max. size max. nb. banks dma type 0 pep0 64 bytes 1 n control 1 pep1 512 bytes 2 y isochronous/bulk/interrupt/control 2 pep2 512 bytes 2 y isochronous/bulk/interrupt/control 3 pep3 512 bytes 2 y isochronous/bulk/interrupt 4 pep4 512 bytes 2 y isochronous/bulk/interrupt/control 5 pep5 512 bytes 2 y isochronous/bulk/interrupt/control 6 pep6 512 bytes 2 y isochronous/bulk/interrupt/control 7 pep7 512 bytes 2 y isochronous/bulk/interrupt/control table 26-2. example of configuration of pipes/endpoints using the whole dpram pipe/endpoint mnemonic size nb. banks 0pep064 bytes1
637 32072d?04/2011 at32uc3a3/a4 26.3 block diagram the usbb provides a hardware device to interface a usb link to a data flow stored in a dual-port ram (dpram). the utmi transceiver requires an external 12mhz clock as a reference to its internal 480mhz pll. the internal 480mhz pll is used to clock an internal dll module to recover the usb dif- ferential data at 480mbit/s. figure 26-1. usbb block diagram 1 pep1 512 bytes 2 2 pep2 512 bytes 2 3 pep3 256 bytes 1 table 26-2. example of configuration of pipes/endpoints using the whole dpram pipe/endpoint mnemonic size nb. banks hsb mux slave master hsb pb dma hsb0 hsb1 slave local hsb slave interface user interface usb 2.0 core dpram pep allocation usb_vbus dmfs dpfs usb_id usb_vbof i/o controller utmi dmhs dphs master gclk_usbb
638 32072d?04/2011 at32uc3a3/a4 26.4 application block diagram depending on the usb operating mode (device-only, reduced-host modes) and the power source (bus-powered or self-powered), there are different typical hardware implementations. 26.4.1 device mode 26.4.1.1 bus-powered device figure 26-2. bus-powered device application block diagram usb 2.0 core usb_vbus dmfs dpfs usb_id usb_vbof i/o controller utmi dmhs dphs usb connector vbus d- d+ id gnd 39 ohms 39 ohms 3.3 v regulator vdd
639 32072d?04/2011 at32uc3a3/a4 26.4.1.2 self-powered device figure 26-3. self-powered device ap plication block diagram 26.4.2 host mode figure 26-4. host application block diagram usb 2.0 core usb_vbus dmfs dpfs usb_id usb_vbof i/o controller utmi dmhs dphs usb connector vbus d- d+ id gnd 39 ohms 39 ohms usb 2.0 core usb_vbus dmfs dpfs usb_id usb_vbof i/o controller utmi dmhs dphs usb connector vbus d- d+ id gnd 39 ohms 39 ohms 5v dc/dc generator vdd
640 32072d?04/2011 at32uc3a3/a4 26.5 i/o lines description table 26-3. i/o lines description pin name pin description type active level usb_vbof usb vbus on/off: bus po wer control port output vbuspo usb_vbus vbus: bus power measurement port input dmfs fs data -: full-speed differential data line - port input/output dpfs fs data +: full-speed differential data line + port input/output dmhs hs data -: hi-speed different ial data line - port input/output dphs hs data +: hi-speed differential data line + port input/output usb_id usb identification: mini connector identification port input low: mini-a plug high z: mini-b plug
641 32072d?04/2011 at32uc3a3/a4 26.6 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 26.6.1 i/o lines the usb_vbof and usb_id pins are multiplexed with i/o controller lines and may also be multiplexed with lines of other peripherals. in order to use them with the usb, the user must first configure the i/o controller to assign them to their usb peripheral functions. if usb_id is used, the i/o controller must be configured to enable the internal pull-up resistor of its pin. if usb_vbof or usb_id is not used by the app lication, the corresponding pin can be used for other purposes by the i/o controller or by other peripherals. 26.6.2 clocks the clock for the usbb bus interface (clk_u sbb) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to dis- able the usbb before disablin g the clock, to avoid freezing the usbb in an undefined state. the utmi transceiver needs a 12mhz clock as a clock reference for its internal 480mhz pll. before using the usb, the user must ensure that this 12mhz clock is available. the 12mhz input is connected to a generic clock (g clk_usbb) provided by the power manager. 26.6.3 interrupts the usbb interrupt request line is connected to the interrupt controller. using the usbb inter- rupt requires the interrupt controller to be programmed first.
642 32072d?04/2011 at32uc3a3/a4 26.7 functional description 26.7.1 usb general operation 26.7.1.1 introduction after a hardware reset, the usbb is disabled. when enabled, the usbb runs either in device mode or in host mode according to the id detection. if the usb_id pin is not connected to ground, the usb_id pin state bit in the general status register (usbsta.id) is set (the internal pull-up resistor of the usb_id pin must be enabled by the i/o controller) and device mode is engaged. the usbsta.id bit is cleared when a low level has been detected on the usb_id pin. host mode is then engaged. 26.7.1.2 power-on and reset figure 26-5 on page 642 describes the usbb main states. figure 26-5. general states after a hardware reset, the usbb is in the reset state. in this state: ? the macro is disabled. the usbb enable bit in the general control register (usbcon.usbe) is zero. ? the macro clock is stopped in order to minimize power consumption. the freeze usb clock bit in usbcon (usbon.frzclk) is set. ? the utmi is in suspend mode. ? the internal states and registers of the device and host modes are reset. ? the dpram is not cleared and is accessible. ? the usbsta.id bit and the vbus level bit in the ubsta (ubsta.vbus) reflect the states of the usb_id and usb_vbus input pins. ? the otg pad enable (otgpade) bit, the vbus polarity (vbuspo) bit, the frzclk bit, the usbe bit, the usb_id pin enable (uide) bi t, the usbb mode (uimod) bit in usbcon, and the low-speed mode force bit in the device general control (udcon.ls) register can be written by software, so that the user can program pads and speed before enabling the macro, but their value is only taken into account once the macro is enabled and unfrozen. device reset usbe = 0 usbe = 1 id = 1 macro off: usbe = 0 clock stopped: frzclk = 1 usbe = 0 host usbe = 0 hw reset usbe = 1 id = 0
643 32072d?04/2011 at32uc3a3/a4 after writing a one to usbcon.u sbe, the usbb enters the device or the host mode (according to the id detectio n) in idle state. the usbb can be disabled at any time by writin g a zero to usbcon.usbe. in fact, writing a zero to usbcon.usbe acts as a hardware reset, except that the otgpade, vbuspo, frzclk, uide, uimod and, ls bits are not reset. 26.7.1.3 interrupts one interrupt vector is assigned to the usb interface. figure 26-6 on page 644 shows the struc- ture of the usb interrupt system.
644 32072d?04/2011 at32uc3a3/a4 figure 26-6. interrupt system see section 26.7.2.19 and section 26.7.3.13 for further details about device and host interrupts. there are two kinds of general interrupts: processing, i.e. their generation is part of the normal processing, and exception, i.e. errors (not related to cpu exceptions). usbcon.idte usbsta.idti usbsta.vbusti usbcon.vbuste usbsta.srpi usbcon.srpe usbsta.vberri usbcon.vberre usbsta.bcerri usbcon.bcerre usbsta.roleexi usbcon.roleexe usbsta.hnperri usbcon.hnperre usbsta.stoi usbcon.stoe usb general interrupt usb device interrupt usb host interrupt usb interrupt asynchronous interrupt source udinte.suspe udint.susp udint.sof udinte.sofe udint.eorst udinte.eorste udint.wakeup udinte.wakeupe udint.eorsm udinte.eorsme udint.uprsm udinte.uprsme udint.epxint udinte.epxinte udint.dmaxint udinte.dmaxinte uhinte.dconnie uhint.dconni uhint.ddisci uhinte.ddiscie uhint.rsti uhinte.rstie uhint.rsmedi uhinte.rsmedie uhint.rxrsmi uhinte.rxrsmie uhint.hsofi uhinte.hsofie uhint.hwupi uhinte.hwupie uhint.pxint uhinte.pxinte uhint.dmaxint uhinte.dmaxinte ueconx.txine uestax.txini uestax.rxouti ueconx.rxoute uestax.rxstpi ueconx.rxstpe uestax.underfi ueconx.underfe uestax.nakouti ueconx.nakoute uestax.nakini ueconx.nakine uestax.overfi ueconx.overfe uestax.stalledi ueconx.stallede uestax.crcerri ueconx.crcerre uestax.shortpacket ueconx.shortpackete uestax.dtseq=mdata & uestax.rxouti ueconx.mdatae upconx.rxine upstax.rxini upstax.txouti upconx.txoute upstax.txstpi upconx.txstpe upstax.underfi upconx.underfie upstax.perri upconx.perre upstax.nakedi upconx.nakede upstax.overfi upconx.overfie upstax.rxstalldi upconx.rxstallde upstax.crcerri upconx.crcerre upstax.shortpacketi upconx.shortpacketie upstax.nbusybk upconx.nbusybke uddmax_control.eot_irq_en uddmax_status.eot_sta uddmax_status.eoch_buff_sta uddmax_control.eobuff_irq_en uddmax_status.desc_ld_sta uddmax_control.desc_ld_irq_en uhdmax_control.eot_irq_en uhdmax_status.eot_sta uhdmax_status.eoch_buff_sta uhdmax_control.eobuff_irq_en uhdmax_status.desc_ld_sta uhdmax_control.desc_ld_irq_en usb device endpoint x interrupt usb host pipe x interrupt usb device dma channel x interrupt usb host dma channel x interrupt udinte.msofe udint.msof uestax.hbisoinerri ueconx.hbisoinerre uestax.hbisoflushi ueconx.hbisoflushe uestax.dtseq=datax & uestax.rxouti ueconx.dataxe uestax.transerr ueconx.transerre uestax.nbusybk ueconx.nbusybke
645 32072d?04/2011 at32uc3a3/a4 the processing general interrupts are: ? the id transition interrupt (idti) ? the vbus transition interrupt (vbusti) ? the role exchange interrupt (roleexi) the exception general interrupts are: ? the vbus error interrupt (vberri) ? the b-connection error interrupt (bcerri) ? the suspend time-out interrupt (stoi) 26.7.1.4 mcu power modes ?run mode in this mode, all mcu clocks can run, including the usb clock. ?idle mode in this mode, the cpu is halted, i.e. the cpu clock is stopped. the idle mode is entered what- ever the state of the usbb. the mcu wakes up on any usb interrupt. ?frozen mode same as the idle mode, except that the hsb module is stopped, so the usb dma, which is an hsb master, can not be used. moreover, the usb dma must be stopped before entering this sleep mode in order to avoid erratic behavior. the mcu wakes up on any usb interrupt. ?standby, stop, deepstop and static modes same as the frozen mode, except that the usb generic clock and other clocks are stopped, so the usb macro is frozen. only the asynchrono us usb interrupt sources can wake up the mcu in these modes (1) . the power manager (pm) may have to be configured to enable asynchro- nous wake up from usb. the usb module must be frozen by writing a one to the frzclk bit. note: 1. when entering a sleep mode deeper or equal to deepstop , the vbus asynchronous interrupt can not be triggered because the bandgap voltage reference is off. thus this interrupt should be disabled (usbcon.vbuste = 0). ?usb clock frozen in the run, idle and frozen mcu modes, the usbb can be frozen when the usb line is in the sus- pend mode, by writing a one to the frzclk bit, what reduces power consumption. in deeper mcu power modes (from standby mode), the usbc must be frozen. in this case, it is still possible to access the following elements, bu t only in run mode: ? the otgpade, vbuspo, frzclk, usbe, uide, uimod and ls bits in the usbcon register ? the dpram (through the usb pipe/endpoint n fifo data (usbfifondata) registers, but not through usb bus transfers which are frozen)
646 32072d?04/2011 at32uc3a3/a4 moreover, when frzclk is written to one, only the asynchronous interrupt sources may trigger the usb interrupt: ? the id transition interrupt (idti) ? the vbus transition interrupt (vbusti) ? the wake-up interrupt (wakeup) ? the host wake-up interrupt (hwupi) ?usb suspend mode in peripheral mode, the suspend interrupt bit in the device global interrupt register (udint.susp)indicates that the usb line is in the suspend mode. in this case, the transceiver is automatically set in suspend mode to reduce the consumption.the 480mhz internal pll is stopped. the usbsta.clkusable bit is cleared. 26.7.1.5 speed control ?device mode when the usb interface is in device mode, the s peed selection (full-speed or high-speed) is per- formed automatically by the usbb during the u sb reset accordin g to the host speed capability. at the end of the usb reset, the usbb enables or disables hi gh-speed terminati ons and pull-up. it is possible to rest raint the usbb to full-spee d or low-speed mode by handling the ls and the speed configuration (spdconf) bits in udcon. ?host mode when the usb interface is in host mode, internal pull-down resistors are connected on both d+ and d- and the interface detects the speed of the connected device, which is reflected by the speed status (speed) field in usbsta. 26.7.1.6 dpram management pipes and endpoints can only be allocated in ascending order (from the pipe/endpoint 0 to the last pipe/endpoint to be allocated). the user shall therefore configure them in the same order. the allocation of a pipe/endpoint n starts when the endpoint memory allocate bit in the endpoint n configuration register (uecfgn.alloc) is written to one. then, the hardware allocates a memory area in the dpram and inserts it between the n-1 and n+1 pipes/endpoints. the n+1 pipe/endpoint memory window slides up and its data is lost. note that the following pipe/end- point memory windows (from n+2) do not slide. disabling a pipe, by writing a zero to the pi pe n enable bit in the pipe enable/reset register (uprst.penn), or disabling an endpoint, by writi ng a zero to the endpoint n enable bit in the endpoint enable/reset register (uerst.epenn), resets neither the uecfgn.alloc bit nor its configuration (the pi pe banks (pbk) field, the pipe size (psize) field, the pipe token (pto- ken) field, the pipe type (ptype) field, th e pipe endpoint number (p epnum) field, and the pipe interrupt request frequency (intfrq) field in the pipe n configuration (upcfgn) regis- ter/the endpoint banks (epbk) field, the endpoint size (epsize) field, the endpoint direction (epdir) field, and the endpoint type (eptype) field in uecfgn).
647 32072d?04/2011 at32uc3a3/a4 to free its memory, the user shall write a zero to the uecfgn.alloc bit. the n+1 pipe/end- point memory window then slides down and its data is lost. note that the following pipe/endpoint memory windows (from n+2) does not slide. figure 26-7 on page 647 illustrates the a llocation and reorganization of the dpram in a typical example. figure 26-7. allocation and reorganization of the dpram 1. the pipes/endpoints 0 to 5 are enabled, configured and allocated in ascending order. each pipe/endpoint then owns a memory area in the dpram. 2. the pipe/endpoint 3 is disabled, but its memory is kept allocated by the controller. 3. in order to free its memory, its alloc bit is written to zero. the pipe/endpoint 4 mem- ory window slides down, but the pipe/endpoint 5 does not move. 4. if the user chooses to reconfigure the pipe/endpoint 3 with a larger size, the controller allocates a memory area after the pipe/endpoint 2 memory area and automatically slides up the pipe/endpoint 4 memory window. the pipe/endpoint 5 does not move and a memory conflict appears as the memory windows of the pipes/endpoints 4 and 5 overlap. the data of these pipes/endpoints is potentially lost. note that: ? there is no way the data of the pipe/endpoint 0 can be lost (except if it is de-allocated) as memory allocation and de-allocation may affect only higher pipes/endpoints. ? deactivating then reactivating a same pipe/endpoint with the same configuration only modifies temporarily the controller dpram poi nter and size for this pipe/endpoint, but nothing changes in the dpram, so higher endpoints seem to not have been moved and their data is preserved as far as nothing has been written or received into them while changing the allocation state of the first pipe/endpoint. ? when the user write a one to the alloc bit, the configuration ok status bit in the endpoint n status register (uestan.cfgok) is set only if the configured size and number of banks are correct compared to their maximal allowed values for the endpoint and to the maximal free memory pep0 pep1 pep2 pep3 pep4 pep5 u(p/e)rst.(e)penn = 1 u(p/e)cfgn.alloc = 1 free memory pep0 pep1 pep2 pep4 pep5 free memory pep0 pep1 pep2 pep4 pep5 pipe/endpoint 3 disabled pipe/endpoint 3 memory freed free memory pep0 pep1 pep2 pep3 (larger size) pep5 pipe/endpoint 3 activated pep4 lost memory pep4 conflict u(p/e)rst.(e)pen3 = 0 pep3 (alloc stays at 1) u(p/e)cfg3.alloc = 0 u(p/e)rst.(e)pen3 = 1 u(p/e)cfg3.alloc = 1 pipes/endpoints 0..5 activated
648 32072d?04/2011 at32uc3a3/a4 fifo size (i.e. the dpram size), so the value of cfgok does not consider memory allocation conflicts. 26.7.1.7 pad suspend figure 26-8 on page 648 shows the pad behavior. figure 26-8. pad behavior ? in the idle state, the pad is put in low power consumption mode, i.e., the differential receiver of the usb pad is off, and internal pull-down with strong value(15k) are set in both dp/dm to avoid floating lines. ? in the active state, the pad is working. figure 26-9 on page 648 illustrates the pad events leading to a pad state change. figure 26-9. pad events the susp bit is set and the wake-up interrupt (wakeup) bit in udint is cleared when a usb ?suspend? state has been detected on the usb bus . this event automatically puts the usb pad in the idle state. t he detection of a non-idle event sets wakeup, cl ears susp and wakes up the usb pad. idle active usbe = 1 & detach = 0 & suspend usbe = 0 | detach = 1 | suspend susp suspend detected cleared on wake-up wake-up detected cleared by software to acknowledge the interrupt wakeup pad state active idle active
649 32072d?04/2011 at32uc3a3/a4 moreover, the pad goes to the idle state if the ma cro is disabled or if the detach bit is written to one. it returns to the active state when usbe is written to one and deta ch is written to zero. 26.7.1.8 plug-in detection the usb connection is detected from the usb_vbus pad. figure 26-10 on page 649 shows the architecture of the plug-in detector. figure 26-10. plug-in detection input block diagram the control logic of the usb_vbus pad outputs two signals: ? the session_valid signal is high when the voltage on the usb_vbus pad is higher than or equal to 1.4v. ? the va_vbus_valid signal is high when the voltage on the usb_vbus pad is higher than or equal to 4.4v. in device mode, the usbsta.vbus bit follows the session_valid comparator output: ? it is set when the voltage on the usb_vbus pad is higher than or equal to 1.4v. ? it is cleared when the voltage on the vbus pad is lower than 1.4v. in host mode, the usbsta.vbu s bit follows an hysteresis based on session_valid and va_vbus_valid: ? it is set when the voltage on the usb_vbus pad is higher than or equal to 4.4v. ? it is cleared when the voltage on the usb_vbus pad is lower than 1.4v. the vbus transition interrupt (vbusti) bit in usbsta is set on each transition of the usb- sta.vbus bit. the usbsta.vbus bit is effective wh ether the usbb is enabled or not. 26.7.1.9 id detection figure 26-11 on page 650 shows how the id transitions are detected. vbusti usbsta usb_vbus vbus usbsta gnd vdd pad logic logic session_valid va_vbus_valid r pu r pd vbus_pulsing vbus_discharge
650 32072d?04/2011 at32uc3a3/a4 figure 26-11. id detection input block diagram the usb mode (device or host) can be either detected from the usb_id pin or software selected by writing to the uimod bit, according to the uide bit. this allows the usb_id pin to be used as a general purpose i/o pin even when the usb interface is enabled. by default, the usb_id pin is se lected (uide is writte n to one) and the usbb is in device mode (ubsta.id is one), what corresponds to the ca se where no mini-a plug is connected, i.e. no plug or a mini-b plug is connected and the usb_id pin is kept high by the internal pull-up resis- tor from the i/o controller (which must be enabled if usb_id is used). the id transition interrupt (idti) bit in usbsta is set on each transition of the id bit, i.e. when a mini-a plug (host mode) is connected or disconne cted. this does not occur when a mini-b plug (device mode) is connected or disconnected. the usbsta.id bit is effective wh ether the usbb is enabled or not. r pu uimod usbcon usb_id id usbsta vdd uide usbcon 1 0 idti usbsta i/o controller
651 32072d?04/2011 at32uc3a3/a4 26.7.2 usb device operation 26.7.2.1 introduction in device mode, the usbb supports hi- full- and low-speed data transfers. in addition to the default control endpoint, seven endpoints are provided, which can be config- ured with the types isochronous, bulk or interrupt, as described in . table 26-1 on page 636 . the device mode starts in the idle state, so the pad consumption is reduced to the minimum. 26.7.2.2 power-on and reset figure 26-12 on page 651 describes the usbb device mode main states. figure 26-12. device mode states after a hardware reset, the usbb device mode is in the re set state. in this state: ? the macro clock is stopped in order to mini mize power consumption (frzclk is written to one). ? the internal registers of the device mode are reset. ? the endpoint banks are de-allocated. ? neither d+ nor d- is pulled up (detach is written to one). d+ or d- will be pulled up according to the sele cted speed as soon as the detach bit is written to zero and vbus is present. see ?device mode? for further details. when the usbb is enabled (usbe is written to one) in device mode (id is one), its device mode state goes to the idle state with minimal power consumption. this does not require the usb clock to be activated. the usbb device mode can be disa bled and reset at any time by disabling the usbb (by writing a zero to usbe) or when host mode is engaged (id is zero). 26.7.2.3 usb reset the usb bus reset is managed by hardware . it is initiated by a connected host. when a usb reset is detected on the usb line, the following operations are performed by the controller: ? all the endpoints are disabled, except the default control endpoint. reset idle hw reset usbe = 0 | id = 0 usbe = 0 | id = 0 usbe = 1 & id = 1
652 32072d?04/2011 at32uc3a3/a4 ? the default control endpoint is reset (see section 26.7.2.4 for more details). ? the data toggle sequence of the default control endpoint is cleared. ? at the end of the reset process, the end of reset (eorst) bit in udint interrupt is set. ? during a reset, the usbb automatically swit ches to the hi-speed mode if the host is hi- speed capable (the reset is called a hi-speed reset). the user should observe the usbsta.speed field to know the speed running at the end of the re set (eorst is one). 26.7.2.4 endpoint reset an endpoint can be reset at any time by writing a one to the endpoint n reset (eprstn) bit in the uerst register. this is recommended before using an endpoint upon hardware reset or when a usb bus reset has been received. this resets: ? the internal state machine of this endpoint. ? the receive and transmit bank fifo counters. ? all the registers of this endpoint (uecfgn, uestan, the endpoint n control (ueconn) register), except it s configuration (alloc, epbk, epsize, epdir, eptype) and the data toggle sequence (dtseq) field of the uestan register. note that the interrupt sources located in the uestan register are not cleared when a usb bus reset has been received. the endpoint configuration remains active and the e ndpoint is still enabled. the endpoint reset may be associated with a clear of the data toggle sequence as an answer to the clear_feature usb request. this can be achieved by writing a one to the reset data toggle set bit in the endpoint n control set regi ster (ueconnset.rstdts).(this will set the reset data toggle (rstd) bit in ueconn). in the end, the user has to write a zero to the eprstn bit to complete the reset operation and to start using the fifo. 26.7.2.5 endpoint activation the endpoint is maintained inactive and reset (see section 26.7.2.4 for more details) as long as it is disabled (epenn is written to zero). dtseq is also reset. the algorithm represented on figure 26-13 on page 653 must be followed in order to activate an endpoint.
653 32072d?04/2011 at32uc3a3/a4 figure 26-13. endpoint activation algorithm as long as the endpoint is not correctly configured (cfgok is zero), the controller does not acknowledge the packets sent by the host to this endpoint. the cfgok bit is set only if the configured size and number of banks are correct compared to their maximal allowed values for the endpoint (see table 26-1 on page 636 ) and to the maximal fifo size (i.e. the dpram size). see section 26.7.1.6 for more details about dpram management. 26.7.2.6 address setup the usb device address is set up according to the usb protocol. ? after all kinds of resets, the usb device address is 0. ? the host starts a setup transacti on with a set_address(addr) request. ? the user write this address to the usb address (uadd) field in udcon, and write a zero to the address enable (adden) bit in udco n, so the actual address is still 0. ? the user sends a zero-length in packet from the control endpoint. ? the user enables the recorded usb device address by writing a one to adden. once the usb device address is configured, the controller filters the packets to only accept those targeting the address stored in uadd. uadd and adden shall not be written all at once. uadd and adden are cleared: ? on a hardware reset. ? when the usbb is disabled (usbe written to zero). ? when a usb reset is detected. when uadd or adden is cleared, the default device address 0 is used. endpoint activation cfgok == 1? error yes endpoint activated enable the endpoint. epenn = 1 test if the endpoint configuration is correct. uecfgn eptype epdir epsize epbk alloc configure the endpoint: - type - direction - size - number of banks allocate the configured dpram banks. no
654 32072d?04/2011 at32uc3a3/a4 26.7.2.7 suspend and wake-up when an idle usb bus state has been detected for 3 ms, the controller set the suspend (susp) interrupt bit in udint. the user may then write a one to the frzclk bit to reduce power con- sumption. the mcu can also enter the idle or frozen sleep mode to lower again power consumption. to recover from the suspend mode, the user shall wait for the wake-up (wakeup) interrupt bit, which is set when a non-idle event is detected, then write a zero to frzclk. as the wakeup interrupt bit in udint is set when a non-idle event is detected, it can occur whether the controller is in the suspend mode or not. the susp and wakeup interrupts are thus independent of each other except that one bit is cleared when the other is set. 26.7.2.8 detach the reset value of the detach bit is one. it is possible to initiate a device re-enumeration simply by writing a one then a zero to detach. detach acts on the pull-up connections of the d+ and d- pads. see ?device mode? for further details. 26.7.2.9 remote wake-up the remote wake-up request (also known as upstream resume) is the only one the device may send on its own initiative, but the device should have beforehand been allowed to by a device_remote_wakeup re quest from the host. ? first, the usbb must have detec ted a ?suspend? state on the bus, i.e. the remote wake-up request can only be sent after a susp interrupt has been set. ? the user may then write a one to the remote wake-up (r mwkup) bit in udcon to send an upstream resume to the host fo r a remote wake-up. this will automatically be done by the controller after 5ms of inactivity on the usb bus. ? when the controller sends the upstream resume, the upstream resume (uprsm) interrupt is set and susp is cleared. ? rmwkup is cleared at the end of the upstream resume. ? if the controller detects a valid ?end of resume? signal from the host, the end of resume (eorsm) interrupt is set. 26.7.2.10 stall request for each endpoint, the stall management is performed using: ? the stall request (stallrq) bit in ueconn to initiate a stall request. ? the stalled interrupt (stalledi) bit in uestan is set when a stall handshake has been sent. to answer the next request with a stall handshake, stallrq has to be set by writing a one to the stall request set (stallrqs) bit. a ll following requests will be discarded (rxouti, etc. will not be set) and handshaked with a stal l until the stallrq bit is cleared, what is done when a new setup packet is received (for control endpoints) or when the stall request clear (stallrqc) bit is written to one. each time a stall handshake is sent, the st alledi bit is set by the usbb and the epnint interrupt is set.
655 32072d?04/2011 at32uc3a3/a4 ?special considerations for control endpoints if a setup packet is received into a control endpoint for which a stall is requested, the received setup interrupt (rxstpi) bit in uest an is set and stallrq and stalledi are cleared. the setup has to be acked. this management simplifies the enumeration process management. if a command is not sup- ported or contains an error, the user requests a stall and can return to the main task, waiting for the next setup request. ?stall handshake and retry mechanism the retry mechanism has priority over the stall handshake. a stall handshake is sent if the stallrq bit is set and if there is no retry required. 26.7.2.11 management of control endpoints ?overview a setup request is always acked. when a new setup packet is received, the rxstpi is set, but not the received out data interrupt (rxouti) bit. the fifo control (fifocon) bi t in ueconn and the read/write allowed (rwall) bit in uestan are irrelevant for control endpoints. the user shall therefore never use them on these endpoints. when read, their value are always zero. control endpoints are managed using: ? the rxstpi bit which is set when a new setup packet is received and which shall be cleared by firmware to acknowledge the packet and to free the bank. ? the rxouti bit which is set when a new out packet is received and which shall be cleared by firmware to acknowledge the packet and to free the bank. ? the transmitted in data interrupt (txini) bit which is set when the current bank is ready to accept a new in packet and which shall be cleared by firmware to send the packet. ?control write figure 26-14 on page 656 shows a control write transaction. during the status stage, the control- ler will not necessarily send a nak on the first in token: ? if the user knows the exact number of descriptor bytes that must be read, it can then anticipate the status stage and send a zero-length packet after the next in token. ? or it can read the bytes and wait for the naked in interrupt (nakini) which tells that all the bytes have been sent by the host and that the transaction is now in the status stage.
656 32072d?04/2011 at32uc3a3/a4 figure 26-14. control write ?control read figure 26-15 on page 656 shows a control read transaction. the usbb has to manage the simultaneous write requests from the cpu and the usb host. figure 26-15. control read a nak handshake is always generated on the first status stage command. when the controller detects the status stage, all the data written by the cpu are lost and clear- ing txini has no effect. the user checks if the transmission or the reception is complete. the out retry is always acked. this recepti on sets rxouti and txini. handle this with the following software algorithm: set txini wait for rxouti or txini if rxouti, then clear bit and return if txini, then continue once the out status stage has been received, the usbb waits for a setup request. the setup request has priority over any other r equest and has to be acked. this means that any other bit should be cleared and the fifo reset when a setup is received. the user has to take care of the fact that the byte counter is re set when a zero-length out packet is received. setup rxstpi rxouti txini usb bus hw sw out hw sw out hw sw in in nak sw data setup status setup rxstpi rxouti txini usb bus hw sw in hw sw in out out nak sw sw hw wr enable host wr enable cpu data setup status
657 32072d?04/2011 at32uc3a3/a4 26.7.2.12 management of in endpoints ?overview in packets are sent by the usb device contro ller upon in requests from the host. all the data can be written which acknowledges or not the bank when it is full. the endpoint must be configured first. the txini bit is set at the same time as fifocon when the current bank is free. this triggers an epnint interrupt if the transmitted in data interrupt enable (txine) bit in ueconn is one. txini shall be cleared by software (by writing a one to the transmitted in data interrupt enable clear bit in the endpoint n control clear regi ster (ueconnclr.txinic)) to acknowledge the interrupt, what has no effect on the endpoint fifo. the user then writes into the fifo (see ?usb pipe/endpoint n fifo data register (usbfifon- data)? on page 759 ) and write a one to the fifo control clear (f ifoconc) bit in ueconnclr to clear the fifocon bit. this allows the usbb to send the data. if the in end- point is composed of multiple banks, this al so switches to the next bank. the txini and fifocon bits are updated in accordance with the status of the next bank. txini shall always be cleared before clearing fifocon. the rwall bit is set when the current bank is no t full, i.e. the software can write further data into the fifo. figure 26-16. example of an in endpoint with 1 data bank in data (bank 0) ack txini fifocon hw write data to cpu bank 0 sw sw sw sw in nak write data to cpu bank 0
658 32072d?04/2011 at32uc3a3/a4 figure 26-17. example of an in endpoint with 2 data banks ?detailed description the data is written, following the next flow: ? when the bank is empty, txini and fifocon are set, what triggers an epnint interrupt if txine is one. ? the user acknowledges the interrupt by clearing txini. ? the user writes the data into the current ba nk by using the usb pipe/endpoint nfifo data virtual segment (see ?usb pipe/endpoint n fifo data register (usbfifondata)? on page 759 ), until all the data frame is written or the bank is full (in which case rwall is cleared and the byte count (byct) field in uestan reaches the endpoint size). ? the user allows the controller to send the bank and switches to the next bank (if any) by clearing fifocon. if the endpoint uses several banks, the current one can be written while the previous one is being read by the host. then, when the user clears fifocon, the following bank may already be free and txini is set immediately. an ?abort? stage can be produced when a zero-length out packet is received during an in stage of a control or isochronou s in transaction. the kill in ba nk (killbk) bit in ueconn is used to kill the last written bank. the best way to man age this abort is to apply the algorithm rep- resented on figure 26-18 on page 659 . see ?endpoint n control register? on page 718 to have more details about the killbk bit. in data (bank 0) ack txini fifocon write data to cpu bank 0 sw sw sw sw in data (bank 1) ack write data to cpu bank 1 sw hw write data to cpu bank0
659 32072d?04/2011 at32uc3a3/a4 figure 26-18. abort algorithm 26.7.2.13 management of out endpoints ?overview out packets are sent by the host. all the data can be read which acknowledges or not the bank when it is empty. the endpoint must be configured first. the rxouti bit is set at the same time as fifo con when the current bank is full. this triggers an epnint interrupt if the re ceived out data interrupt enab le (rxoute) bit in ueconn is one. rxouti shall be cleared by soft ware (by writing a one to the re ceived out data interrupt clear (rxoutic) bit) to acknowledge the interrupt, what has no effect on the endpoint fifo. the user then reads from the fifo (see ?usb pipe/endpoint n fifo data register (usbfifon- data)? on page 759 ) and clears the fifocon bit to free the bank. if the out endpoint is composed of multiple banks, this also switches to the next bank. the rxouti and fifocon bits are updated in accordance with the status of the next bank. rxouti shall always be cleared before clearing fifocon. the rwall bit is set when the current bank is not empty, i.e. the software can read further data from the fifo. endpoint abort abort done abort is based on the fact that no bank is busy, i.e., that nothing has to be sent disable the txini interrupt. eprstn = 1 nbusybk == 0? yes txinec = 1 no killbks = 1 killbk == 1? yes kill the last written bank. wait for the end of the procedure no
660 32072d?04/2011 at32uc3a3/a4 figure 26-19. example of an out endpoint with one data bank figure 26-20. example of an out endpoint with two data banks ?detailed description the data is read, following the next flow: ? when the bank is full, rxouti and fifocon are set, what triggers an epnint interrupt if rxoute is one. ? the user acknowledges the interrupt by writing a one to rxoutic in order to clear rxouti. ? the user can read the byte count of the current bank from byct to know how many bytes to read, rather than polling rwall. ? the user reads the data from the current bank by using the usbfifondata register (see ?usb pipe/endpoint n fifo data register (usbfifondata)? on page 759 ), until all the expected data frame is read or the bank is em pty (in which case rwall is cleared and byct reaches zero). ? the user frees the bank and switches to the next bank (if any) by clearing fifocon. if the endpoint uses several banks, the current one can be read while the following one is being written by the host. then, when the user clears fifocon, the following bank may already be ready and rxouti is set immediately. in hi-speed mode, the ping and nyet protocol is handled by the usbb. for single bank, a nyet handshake is always sent to the host (on bulk-out transaction) to indicate that the current packet is acknowledged but there is no room for the next one. for double bank, the usbb out data (bank 0) ack rxouti fifocon hw out data (bank 0) ack hw sw sw sw read data from cpu bank 0 read data from cpu bank 0 nak out data (bank 0) ack rxouti fifocon hw out data (bank 1) ack sw sw read data from cpu bank 0 hw sw read data from cpu bank 1
661 32072d?04/2011 at32uc3a3/a4 responds to the out/data transaction with an ack handshake when the endpoint accepted the data successfully and has room for another data payload (the second bank is free). 26.7.2.14 underflow this error exists only for isochronous in/out endpoints. it set the underflow interrupt (underfi) bit in uestan, what triggers an epni nt interrupt if the underflow interrupt enable (underfe) bit is one. an underflow can occur during in stage if the host attempts to read from an empty bank. a zero- length packet is then auto matically sent by the usbb. an underflow can not occur during out stage on a cpu action, since the user may read only if the bank is not empty (rxouti is one or rwall is one). an underflow can also occur during out stage if the host sends a packet while the bank is already full. typically, the cpu is not fast enough. the packet is lost. an underflow can not occur during in stage on a cp u action, since the user may write only if the bank is not full (txini is one or rwall is one). 26.7.2.15 overflow this error exists for all endpoint types. it set the overflow interrupt (overfi) bit in uestan, what triggers an epnint interrupt if the overflow interrupt enable (overfe) bit is one. an overflow can occur during out stage if the host attempts to write into a bank that is too small for the packet. the packet is acknowledged and the rxouti bit is set as if no overflow had occurred. the bank is filled with all the first bytes of the packet that fit in. an overflow can not occur during in stage on a cpu action, since the user may write only if the bank is not full (txini is one or rwall is one). 26.7.2.16 hb isoin error this error exists only for high-bandwidth isochrono us in endpoints if the high-bandwidth isochro- nous feature is supported by the device (see the ufeatures register for this). at the end of the micro-frame, if at least one packet has been sent to the host, if less banks than expected has been validated (by clearing the fifo con) for this micro-frame, it set the hbisoinerrori bit in uestan, what triggers an epnint interrupt if the high bandwidth iso- chronous in error interrupt enable (hbisoinerrore) bit is one. for instance, if the number of transaction per microframe for isochronous endpoint (nbtrans field in uecfgn is three (three tr ansactions per micro-frame), only two banks are filled by the cpu (three expected ) for the current micro-frame. then, the hbisoi nerri interrupt is generated at the end of the micro-frame. note that an underfi interrupt is also generated (with an automatic zero-length-packet), except in the case of a missing in token. 26.7.2.17 hb isoflush this error exists only for high-bandwidth isochrono us in endpoints if the high-bandwidth isochro- nous feature is supported by the device (see the ufeatures register for this). at the end of the micro-frame, if at least one packet has been sent to the host, if there is missing in token during this micro-frame, the bank(s) destined to this micro-frame is/are flushed out to ensure a good data synchronization between the host and the device.
662 32072d?04/2011 at32uc3a3/a4 for instance, if nbtrans is three (three transactions per micro-frame), if only the first in token (among 3) is well received by the usbb, th en the two last banks will be discarded. 26.7.2.18 crc error this error exists only for isochronous out endp oints. it set the crc error interrupt (crcerri) bit in uestan, what triggers an epnint interrupt if the crc error interrupt enable (crcerre) bit is one. a crc error can occur during out stage if the usbb detects a corrupted received packet. the out packet is stored in the bank as if no crc error had occurred (rxouti is set). 26.7.2.19 interrupts see the structure of the usb device interrupt system on figure 26-6 on page 644 . there are two kinds of device interrupts: processing, i.e. their generation is part of the normal processing, and exception, i.e. errors (not related to cpu exceptions). ?global interrupts the processing device global interrupts are: ? the suspend (susp) interrupt ? the start of frame (sof) interrupt with no frame number crc error (the frame number crc error (fncerr) bit in the device fram e number (udfnum) register is zero) ? the micro start of frame (mso f) interrupt with no crc error. ? the end of reset (eorst) interrupt ? the wake-up (wakeup) interrupt ? the end of resume (eorsm) interrupt ? the upstream resume (uprsm) interrupt ? the endpoint n (epnint) interrupt ? the dma channel n (dmanint) interrupt the exception device global interrupts are: ? the start of frame (sof) interrupt with a frame number crc error (fncerr is one) ? the micro start of frame (msof) interrupt with a crc error ?endpoint interrupts the processing device endpoint interrupts are: ? the transmitted in data interrupt (txini) ? the received out data interrupt (rxouti) ? the received setup interrupt (rxstpi) ? the short packet (shortpacket) interrupt ? the number of busy banks (nbusybk) interrupt ? the received out isochronous multiple data interrupt (mdatai) ? the received out isochronous datax interrupt (dataxi) the exception device endpoint interrupts are: ? the underflow interrupt (underfi)
663 32072d?04/2011 at32uc3a3/a4 ? the naked out interrupt (nakouti) ? the high-bandwidth isochronous in error in terrupt (hbisoinerri) if the high-bandwidth isochronous feature is supported by the de vice (see the ufeatures register for this) ? the naked in interrupt (nakini) ? the high-bandwidth isochronous in flush error interrupt (hbisoflushi) if the high- bandwidth isochronous feature is supported by the device (see the ufeatures register for this) ? the overflow interrupt (overfi) ? the stalled interrupt (stalledi) ? the crc error interrupt (crcerri) ? the transaction error (errortrans) interrupt if the high-bandwidth isochronous feature is supported by the device (see the ufeatures register for this) ?dma interrupts the processing device dma interrupts are: ? the end of usb transfer status (eotsta) interrupt ? the end of channel buffer status (eochbuffsta) interrupt ? the descriptor loaded status (descldsta) interrupt there is no exception device dma interrupt. 26.7.2.20 test modes when written to one, the udcon.tstpckt bit swit ches the usb device controller in a ?test packet?mode: the transceiver repeatedly transmit the packet stored in the current bank. tstpckt must be written to zero to exit the ?test-packet? mode. the endpoint shall be reset by software after a ?test-packet? mode. this enables the testing of rise and falling times, eye patterns , jitter, and any other dynamic waveform specifications. the flow control used to send the packets is as follows: ? tstpckt=1; ? store data in an endpoint bank ? write a zero to fifocon bit to stop the test-packet mode, just write a zero to the tstpckt bit.
664 32072d?04/2011 at32uc3a3/a4 26.7.3 usb host operation 26.7.3.1 description of pipes for the usbb in host mode, the term ?pipe? is used instead of ?end point? (used in device mode). a host pipe corresponds to a device endpoint, as described by the figure 26-21 on page 664 from the usb specification. figure 26-21. usb communication flow in host mode, the usbb associates a pipe to a device endpoint, considering the device configu- ration descriptors. 26.7.3.2 power-on and reset figure 26-22 on page 664 describes the usbb host mode main states. figure 26-22. host mode states after a hardware reset, the usbb hos t mode is in the reset state. when the usbb is enabled (usbe is one) in host mode (id is zero ), its host mode state goes to the idle state. in this state, the controller waits for device connection with minimal power con- ready idle device disconnection device connection macro off clock stopped device disconnection suspend sofe = 1 sofe = 0
665 32072d?04/2011 at32uc3a3/a4 sumption. the usb pad should be in the idle state. once a device is connected, the macro enters the ready state, what does not require the usb clock to be activated. the controller enters the suspend state when the usb bus is in a ?suspend? state, i.e., when the host mode does not generate the ?start of frame (sof)?. in this state, the usb consumption is minimal. the host mode exits the suspend st ate when starting to generate the sof over the usb line. 26.7.3.3 device detection a device is detected by the usbb host mode w hen d+ or d- is no longer tied low, i.e., when the device d+ or d- pull-up resistor is connected. to enable this detection, the host controller has to provide the vbus power supply to the device by setting the vbusrq bit (by writing a one to the vbusrqs bit). the device disconnection is detected by the host controller when both d+ and d- are pulled down. 26.7.3.4 usb reset the usbb sends a usb bus reset when the user write a one to the send usb reset bit in the host general control register (uhcon.reset). the usb reset sent interrupt bit in the host global interrupt register (uhint.rsti) is set when the usb reset has been sent. in this case, all the pipes are disabled and de-allocated. if the bus was previously in a ?suspend? state (the start of frame generation enable (sofe) bit in uhcon is zero), the usbb automatically switc hes it to the ?resume? state, the host wake- up interrupt (hwupi) bit in uhint is set and the sofe bit is set in order to generate sofs or micro sofs immediately after the usb reset. at the end of the reset, the user should check the usbsta.speed field to know the speed run- ning according to the peripheral ca pability (ls.fs/hs) 26.7.3.5 pipe reset a pipe can be reset at any time by writing a one to the pipe n reset (prstn) bit in the uprst register. this is recommended before using a pipe upon hardware reset or when a usb bus reset has been sent. this resets: ? the internal state machine of this pipe ? the receive and transmit bank fifo counters ? all the registers of this pipe (upcfgn, upstan , upconn), except its configuration (alloc, pbk, psize, ptoken, ptype, pepnum, intfrq in upcfgn) and its data toggle sequence field in the pipe n status register (upstan.dtseq). the pipe configuration remains acti ve and the pipe is still enabled. the pipe reset may be associated with a clear of the data toggle sequence. this can be achieved by setting the reset data toggle bit in the pipe n control register (upconn.rstdt) (by writing a one to the reset data toggle set bit in the pipe n control set register (upconnset.rstdts)). in the end, the user has to write a zero to the prstn bit to complete the reset operation and to start using the fifo.
666 32072d?04/2011 at32uc3a3/a4 26.7.3.6 pipe activation the pipe is maintained inactive and reset (see section 26.7.3.5 for more details) as long as it is disabled (penn is zero). the data toggle sequence field (dtseq) is also reset. the algorithm represented on figure 26-23 on page 666 must be followed in order to activate a pipe. figure 26-23. pipe activation algorithm as long as the pipe is not correctly configured (upstan.cfgok is zero), the controller can not send packets to the device through this pipe. the upstan.cfgok bit is set only if the configured size and number of banks are correct com- pared to their maximal allowed values for the pipe (see table 26-1 on page 636 ) and to the maximal fifo size (i.e. the dpram size). see section 26.7.1.6 for more details about dpram management. once the pipe is correctly configured (upstan .cfgok is zero), only the ptoken and intfrq fields can be written by software. intfr q is meaningless for non-interrupt pipes. when starting an enumeration, the user gets the device descriptor by sending a get_descriptor usb request. this descripto r contains the maximal packet size of the device default control endpoint (bmaxpacketsize0) and the user re-configures the size of the default control pipe with this size parameter. 26.7.3.7 address setup once the device has answered the first host requests with the default device address 0, the host assigns a new address to the device. the host controller has to send an usb reset to the device and to send a set_address(addr) setup request with the new address to be used by the device. once this setup transaction is over, th e user writes the new address into the usb host address for pipe n field in the usb host devi ce address register (uhaddr.uhaddrpn). all following requests, on all pipes, will be performed using this new address. pipe activation cfgok == 1? error yes pipe activated enable the pipe. penn = 1 test if the pipe configuration is correct. upcfgn intfrq pepnum ptype ptoken psize pbk alloc configure the pipe: - interrupt request frequency - endpoint number - type - size - number of banks allocate the configured dpram banks. no
667 32072d?04/2011 at32uc3a3/a4 when the host controller sends an usb reset, the uhaddrpn field is reset by hardware and the following host requests will be performed using the def ault device address 0. 26.7.3.8 remote wake-up the controller host mode enters the suspend state when the uhcon.sofe bit is written to zero. no more ?start of frame? is sent on the usb bus and the usb device enters the suspend state 3ms later. the device awakes the host by sending an upstream resume (remote wake-up feature). when the host controller detects a non-idle state on the usb bus, it set the host wake-up inter- rupt (hwupi) bit in uhint. if the non-idle bus state corresponds to an upstream resume (k state), the upstream resume received interrupt (rxrsmi) bit in uhint is set. the user has to generate a downstream resume within 1ms and for at least 20ms by writing a one to the send usb resume (resume) bit in uhcon. it is ma ndatory to write a one to uhcon.sofe before writing a one to uhcon.resume to enter the ready state, else uhcon.resume will have no effect. 26.7.3.9 management of control pipes a control transaction is composed of three stages: ? setup ? data (in or out) ? status (out or in) the user has to change the pipe token according to each stage. for the control pipe, and only for it, each token is assigned a specific initial data toggle sequence: ? setup: data0 ? in: data1 ? out: data1 26.7.3.10 management of in pipes in packets are sent by the usb device contro ller upon in requests from the host. all the data can be read which acknowledges or not the bank when it is empty. the pipe must be configured first. when the host requires data from the device, the user has to select beforehand the in request mode with the in request mode bit in the pi pe n in request register (upinrqn.inmode): ? when inmode is written to zero, the usbb w ill perform (inrq + 1) in requests before freezing the pipe. ? when inmode is written to one, the usbb will pe rform in requests endlessly when the pipe is not frozen by the user. the generation of in requests starts when the pipe is unfrozen (the pipe freeze (pfreeze) field in upconn is zero). the received in data interrupt (rxini) bit in upstan is set at the same time as the fifo con- trol (fifocon) bit in upconn when the current bank is full. this triggers a pnint interrupt if the received in data interrupt enable (rxine) bit in upconn is one.
668 32072d?04/2011 at32uc3a3/a4 rxini shall be cleared by software (by writing a one to the received in data interrupt clear bit in the pipe n control clear register(upconnclr.rxinic)) to acknowledge the interrupt, what has no effect on the pipe fifo. the user then reads from the fifo (see ?usb pipe/endpoint n fifo data register (usbfifon- data)? on page 759 ) and clears the fifocon bit (by writing a one to the fifo control clear (fifoconc) bit in upconnclr) to free the bank. if the in pipe is composed of multiple banks, this also switches to the next bank. the rxini and fifocon bits are updated in accordance with the status of the next bank. rxini shall always be clear ed before clearing fifocon. the read/write allowed (rwall) bit in upstan is set when the current bank is not empty, i.e., the software can read further data from the fifo. figure 26-24. example of an in pipe with 1 data bank figure 26-25. example of an in pipe with 2 data banks 26.7.3.11 management of out pipes out packets are sent by the host. all the data can be written which acknowledges or not the bank when it is full. the pipe must be configured and unfrozen first. in data (bank 0) ack rxini fifocon hw in data (bank 0) ack hw sw sw sw read data from cpu bank 0 read data from cpu bank 0 in data (bank 0) ack rxini fifocon hw in data (bank 1) ack sw sw read data from cpu bank 0 hw sw read data from cpu bank 1
669 32072d?04/2011 at32uc3a3/a4 the transmitted out data interrupt (txouti) bit in upstan is set at the same time as fifo- con when the current bank is free. this triggers a pnint interrupt if the transmitted out data interrupt enable (txoute) bit in upconn is one. txouti shall be cleared by software (by writing a one to the transmitted out data interrupt clear (txoutic) bit in upconncl r) to acknowledge the interrupt, what has no effect on the pipe fifo. the user then writes into the fifo (see ?usb pipe/endpoint n fifo data register (usbfifon- data)? on page 759 ) and clears the fifocon bit to allow the usbb to send the data. if the out pipe is composed of multiple banks, this also switches to the next bank. the txouti and fifocon bits are updated in accordance with the status of the next bank. txouti shall always be cleared before clearing fifocon. the upstan.rwall bit is set when the current bank is not full, i.e., the software can write fur- ther data into the fifo. note that if the user decides to switch to the suspend state (by writing a zero to the uhcon.sofe bit) while a bank is ready to be sent, the usbb automatica lly exits this state and the bank is sent. note that in high-speed operating mode, the host controller automatically manages the ping protocol to maximize the usb bandwidth. the user can tune the ping protocol by handling the ping enable (pingen) bit and the binterval pa rameter for the bulk-out/ping transaction (bintervall) field in upcfgn. see the section 26.8.3.12 for more details. figure 26-26. example of an out pipe with one data bank out data (bank 0) ack txouti fifocon hw write data to cpu bank 0 sw sw sw sw out write data to cpu bank 0
670 32072d?04/2011 at32uc3a3/a4 figure 26-27. example of an out pipe with two data banks and no bank switching delay figure 26-28. example of an out pipe with two data banks and a bank switching delay 26.7.3.12 crc error this error exists only for isochronous in pi pes. it set the crc error interrupt (crcerri) bit, what triggers a pnint interrupt if then the crc error interrupt enable (crcerre) bit in upconn is one. a crc error can occur during in stage if the us bb detects a corrupted received packet. the in packet is stored in the bank as if no crc error had occurred (rxini is set). 26.7.3.13 interrupts see the structure of the usb host interrupt system on figure 26-6 on page 644 . there are two kinds of host interrupts: processing, i.e. their generation is part of the normal pro- cessing, and exception, i.e. errors (not related to cpu exceptions). ?global interrupts the processing host global interrupts are: ? the device connection interrupt (dconni) ? the device disconnection interrupt (ddisci) out data (bank 0) ack txouti fifocon write data to cpu bank 0 sw sw sw sw write data to cpu bank 1 sw hw write data to cpu bank0 out data (bank 1) ack out data (bank 0) ack txouti fifocon write data to cpu bank 0 sw sw sw sw out data (bank 1) ack write data to cpu bank 1 sw hw write data to cpu bank0
671 32072d?04/2011 at32uc3a3/a4 ? the usb reset sent interrupt (rsti) ? the downstream resume sent interrupt (rsmedi) ? the upstream resume received interrupt (rxrsmi) ? the host start of frame interrupt (hsofi) ? the host wake-up interrupt (hwupi) ? the pipe n interrupt (pnint) ? the dma channel n interrupt (dmanint) there is no exception host global interrupt. ?pipe interrupts the processing host pipe interrupts are: ? the received in data interrupt (rxini) ? the transmitted out data interrupt (txouti) ? the transmitted setup interrupt (txstpi) ? the short packet interrupt (shortpacketi) ? the number of busy banks (nbusybk) interrupt the exception host pipe interrupts are: ? the underflow interrupt (underfi) ? the pipe error interrupt (perri) ? the naked interrupt (nakedi) ? the overflow interrupt (overfi) ? the received stalled interrupt (rxstalldi) ? the crc error interrupt (crcerri) ?dma interrupts the processing host dma interrupts are: ? the end of usb transfer status (eotsta) interrupt ? the end of channel buffer status (eochbuffsta) interrupt ? the descriptor loaded status (descldsta) interrupt there is no exception host dma interrupt.
672 32072d?04/2011 at32uc3a3/a4 26.7.4 usb dma operation 26.7.4.1 introduction usb packets of any length may be transferred when required by the usbb. these transfers always feature sequential addressing. these two characteristics mean that in case of high usbb throughput, both hsb ports will benefit from ?incrementing burst of unspecified length? since the average access latency of hsb slaves can then be reduced. the dma uses word ?incrementing burst of unspec ified length? of up to 256 beats for both data transfers and channel descriptor loading. a burst may last on the hsb busses for the duration of a whole usb packet transfer, unless otherwise broken by the hsb arbitration or the hsb 1kbyte boundary crossing. packet data hsb bursts may be locked on a dma buffer basis for drastic overall hsb bus band- width performance boost with paged memories. th is is because these memories row (or bank) changes, which are very clock-cycle consuming, will then likely not occur or occur once instead of dozens of times during a single big usb packet dma transfer in case other hsb masters address the memory. this means up to 128 words single cycle unbroken hsb bursts for bulk pipes/endpoints and 256 words si ngle cycle unbroken bursts fo r isochronous pipes/endpoints. this maximal burst length is then controlled by the lowest programmed usb pipe/endpoint size (psize/epsize) and the channel byte length (chbytelength) field in the device dma channel n control (uddm ancontrol) register. the usbb average throughput may be up to nearly 53 mbyte/s. its average access latency decreases as burst length increases due to the zero wait-state side effect of unchanged pipe/endpoint. word access allows reducing the hsb bandwidth required for the usb by four compared to native byte access. if at least 0 wa it-state word burst capability is also provided by the other dma hsb bus slaves, each of both dma hsb busses need less than 60% bandwidth allocation for full usb bandwidth usage at 33mhz, and less than 30% at 66mhz.
673 32072d?04/2011 at32uc3a3/a4 figure 26-29. example of dma chained list 26.7.4.2 dma channel descriptor the dma channel transfer descriptor is loaded from the memory. be careful with the alignment of this buffer. the structure of the dma channel transfer descriptor is defined by three parameters as described below: ? offset 0: ? the address must be aligned: 0xxxxx0 ? dma channel n next descriptor address register: dmannxtdescaddr ? offset 4: ? the address must be aligned: 0xxxxx4 ? dma channel n hsb address register: dmanaddr ? offset 8: ? the address must be aligned: 0xxxxx8 ? dma channel n control register: dmancontrol 26.7.4.3 programming a chanel: each dma transfer is unidirectionnal. direction depends on the type of the associated endpoint (in or out). three registers, the uddmannextdesc , the uddmanaddr and uddmancontrol need to be programmed to set up wether single or multiple transfer is used. the following example refers to out endpoint. for in endpoint, the programming is symmetric. data buffer 1 data buffer 2 data buffer 3 memory area transfer descriptor next descriptor address hsb address control transfer descriptor transfer descriptor usb dma channel x registers (current transfer descriptor) next descriptor address hsb address control null status next descriptor address hsb address control next descriptor address hsb address control
674 32072d?04/2011 at32uc3a3/a4 ?single-block transfer programming example for out transfer : the following sequence may be used: ? configure the targerted endpoint (source) as out type, and set the automatic bank switching for this endpoint in the uecfgn register to handle multiple out packet. ? write the starting destination address in the uddmanaddr register. ? there is no need to progra m the uddmannextdesc register. ? program the channel byte length in the uddmancontrol register. ? program the uddmancontrol acco rding to row 2 as shown in figure 26-6 on page 726 to set up a single block transfer. the uddmanstatus.chen bit is set indicating that the dma channel is enable. as soon as an out packet is stored inside the endpoint, the uddmanstatus.chactive bit is set to one, indicating that the dma channel is transfering data from the endpoint to the desti- nation address until the endpoint is empty or the channel byte length is reached. once the endpoint is empty, the uddmanstatus.chactive bit is cleared. once the dma channel is completed (i.e : the channel byte length is reached), after one or mul- tiple processed out packet, the uddmancontrol.chen bit is cleared. as a consequence, the uddmanstatus.chen bit is also cleare d, and the uddmanstat us.eochbuffsta bit is set indicating a end of dma channel. if the uddmancontrol.dmaenden bit was set, the last endpoint bank will be properly released even if there are some resi dual datas inside, i.e: out packet truncation at the end of dma buffer when the dma channel byte lenght is not an integral multiple of the endpoint size. ?programming example for single-block dma transfer with automatic closure for out transfer : the idea is to automatically close the dma transfer at the end of the out transaction (received short packet). the following sequence may be used: ? configure the targerted endpoint (source) as out type, and set the automatic bank switching for this endpoint in the uecfgn register to handle multiple out packet. ? write the starting destination address in the uddmanaddr register. ? there is no need to progra m the uddmannextdesc register. ? program the channel byte length in the uddmancontrol register. ? set the buffcloseinen bit in the uddmancontrol register. ? program the uddmancontrol acco rding to row 2 as shown in figure 26-6 on page 726 to set up a single block transfer. as soon as an out packet is stored inside the endpoint, the uddmanstatus.chactive bit is set to one, indicating that the dma channel is transfering data from the endpoint to the desti- nation address until the endpoint is empty. once the endpoint is empty, the uddmanstatus.chactive bit is cleared. after one or multiple processed out packet, t he dma channel is completed after sourcing a short packet. then, the uddmanco ntrol.chen bit is cleared. as a consequence, after a few cycles latency, the uddmanstatus.chen bi t is also cleared, and the uddmansta- tus.eotsta bit is set indicating that the dma was closed by a end of usb transaction.
675 32072d?04/2011 at32uc3a3/a4 ?programming example for multi-block dma transfer : run and link at end of buffer the idea is to run first a single block transfer followed automatically by a linked list of dma. the following sequence may be used: ? configure the targerted endpoint (source) as out type, and set the automatic bank switching for this endpoint in the uecfgn register to handle multiple out packet. ? set up the chain of linked list of descripor in memory. each descriptor is composed of 3 items : channel next descriptor address, channel destination address and channel control. the last descriptor should be programmed according to row 2 as shown in figure 26-6 on page 726 . ? write the starting destination address in the uddmanaddr register. ? program the uddmannextdesc register. ? program the channel byte length in the uddmancontrol register. ? optionnaly set the buffcloseinen bit in the uddmancontrol register. ? program the uddmancontrol acco rding to row 4 as shown in figure 26-6 on page 726 . the uddmanstatus.chen bit is set indicating that the dma channel is enable. as soon as an out packet is stored inside the endpoint, the uddmanstatus.chactive bit is set to one, indicating that the dma channel is transfering data from the endpoint to the desti- nation address until the endpoint is empty or the channel byte length is reached. once the endpoint is empty, the uddmanstatus.chactive bit is cleared. once the first dma channel is completed (i.e : the channel byte length is reached), after one or multiple processed out packet, the uddmancontrol.chen bit is cleared. as a conse- quence, the uddmanstatus.chen bit is also cleared, and the uddmanstatus.eochbuffsta bit is set indicating a end of dma channel. if the uddman- control.dmaenden bit was set, the last endpoint b ank will be properly released even if there are some residual datas inside, i.e: out packet truncation at the end of dma buffer when the dma channel byte lenght is not an integral multiple of the endpoint size. note that the uddmancontrol.ldnxtch bit remains to one i ndicating that a linked descriptor will be loaded. once the new descriptor is loaded from the uddmannextdesc memory address, the uddm- anstatus.descldsta bit is set, and the uddm ancontrol register is updated from the memory. as a consequence, the uddmanstatus.chen bit is set, and the uddmansta- tus.chactive is set as soon as the endpoint is ready to be sourced by the dma (received out data packet). this sequence is repeated until a last linked descriptor is processed. the last descriptor is detected according to row 2 as shown in figure 26-6 on page 726 . at the end of the last descriptor, the uddmancontrol.chen bit is cleared. as a conse- quence, after a few cycles latency, the uddmanstatus.chen bit is also cleared. ?programming example for multi-block dma transfer : load next descriptor now the idea is to directly run first a linked list of dma. the following sequence may be used: the following sequence may be used: ? configure the targerted endpoint (source) as out type, and set the automatic bank switching for this endpoint in the uecfgn register to handle multiple out packet.
676 32072d?04/2011 at32uc3a3/a4 ? set up the chain of linked list of descripor in memory. each descriptor is composed of 3 items : channel next descriptor address, channel destination address and channel control. the last descriptor should be programmed according to row 2 as shown in figure 26-6 on page 726 . ? program the uddmannextdesc register. ? program the uddmancontrol acco rding to row 3 as shown in figure 26-6 on page 726 . the uddmanstatus.chen bit is 0 and the uddmanstatus.ldnxtchdescen is set indi- cating that the dma channel is pending until the endpoint is ready (received out packet). as soon as an out packet is stored inside the endpoint, the uddmanstatus.chactive bit is set to one. then after a few cycle latency, the new descriptor is loaded from the memory and the uddmanstatus.descldsta is set. at the end of this dma (for instance when the channel byte length has reached 0), the uddmancontrol.chen bit is cleared, and then the uddmanstatus.chen bit is also cleared. if the uddmanco ntrol.ldnxtch value is one, a new descriptor is loaded. this sequence is repeated until a last linked descriptor is processed. the last descriptor is detected according to row 2 as shown in figure 26-6 on page 726 . at the end of the last descriptor, the uddmancontrol.chen bit is cleared. as a conse- quence, after a few cycles latency, the uddmanstatus.chen bit is also cleared.
677 32072d?04/2011 at32uc3a3/a4 26.8 user interface table 26-4. usbb register memory map offset register name access reset value 0x0000 device general control register udcon read/write 0x00000100 0x0004 device global interrupt register udint read-only 0x00000000 0x0008 device global interrupt clear register udintclr write-only 0x00000000 0x000c device global interrupt se t register udintset write-only 0x00000000 0x0010 device global interrupt enable register udinte read-only 0x00000000 0x0014 device global interrupt enable clear register udinteclr write-only 0x00000000 0x0018 device global interrupt enable set register udinteset write-only 0x00000000 0x001c endpoint enable/reset register uerst read/write 0x00000000 0x0020 device frame number register udfnum read-only 0x00000000 0x0100 endpoint 0 configuration register uecfg0 read/write 0x00002000 0x0104 endpoint 1 configuration register uecfg1 read/write 0x00002000 0x0108 endpoint 2 configuration register uecfg2 read/write 0x00002000 0x010c endpoint 3 configuration register uecfg3 read/write 0x00002000 0x0110 endpoint 4 configuration register uecfg4 read/write 0x00002000 0x0114 endpoint 5 configuration register uecfg5 read/write 0x00002000 0x0118 endpoint 6 configuration register uecfg6 read/write 0x00002000 0x011c endpoint 7configuration r egister uecfg7 read/write 0x00002000 0x0130 endpoint 0 status register uesta0 read-only 0x00000100 0x0134 endpoint 1 status register uesta1 read-only 0x00000100 0x0138 endpoint 2 status register uesta2 read-only 0x00000100 0x013c endpoint 3 status register uesta3 read-only 0x00000100 0x0140 endpoint 4 status register uesta4 read-only 0x00000100 0x0144 endpoint 5 status register uesta5 read-only 0x00000100 0x0148 endpoint 6 status register uesta6 read-only 0x00000100 0x014c endpoint 7status register uesta7 read-only 0x00000100 0x0160 endpoint 0 status clear register uesta0clr write-only 0x00000000 0x0164 endpoint 1 status clear register uesta1clr write-only 0x00000000 0x0168 endpoint 2 status clear register uesta2clr write-only 0x00000000 0x016c endpoint 3 status clear register uesta3clr write-only 0x00000000 0x0170 endpoint 4 status clear register uesta4clr write-only 0x00000000 0x0174 endpoint 5 status clear register uesta5clr write-only 0x00000000 0x0178 endpoint 6 status clear register uesta6clr write-only 0x00000000 0x017c endpoint 7 status clear register uesta7clr write-only 0x00000000 0x0190 endpoint 0 status set r egister uesta0set write-only 0x00000000 0x0194 endpoint 1 status set r egister uesta1set write-only 0x00000000
678 32072d?04/2011 at32uc3a3/a4 0x0198 endpoint 2 status set r egister uesta2set write-only 0x00000000 0x019c endpoint 3 status set r egister uesta3set write-only 0x00000000 0x01a0 endpoint 4 status set r egister uesta4set write-only 0x00000000 0x01a4 endpoint 5 status set r egister uesta5set write-only 0x00000000 0x01a8 endpoint 6 status set r egister uesta6set write-only 0x00000000 0x01ac endpoint 7 status set regi ster uesta7set write-only 0x00000000 0x01c0 endpoint 0 control register uecon0 read-only 0x00000000 0x01c4 endpoint 1 control register uecon1 read-only 0x00000000 0x01c8 endpoint 2 control register uecon2 read-only 0x00000000 0x01cc endpoint 3 control register uecon3 read-only 0x00000000 0x01d0 endpoint 4 control register uecon4 read-only 0x00000000 0x01d4 endpoint 5 control register uecon5 read-only 0x00000000 0x01d8 endpoint 6 control register uecon6 read-only 0x00000000 0x01dc endpoint 7 control register uecon7 read-only 0x00000000 0x01f0 endpoint 0 control set register uecon0set write-only 0x00000000 0x01f4 endpoint 1 control set register uecon1set write-only 0x00000000 0x01f8 endpoint 2 control set register uecon2set write-only 0x00000000 0x01fc endpoint 3 control set register uecon3set write-only 0x00000000 0x0200 endpoint 4 control set register uecon4set write-only 0x00000000 0x0204 endpoint 5 control set register uecon5set write-only 0x00000000 0x0208 endpoint 6 control set register uecon6set write-only 0x00000000 0x020c endpoint 7 control set register uecon7set write-only 0x00000000 0x0220 endpoint 0 control clear register uecon0clr write-only 0x00000000 0x0224 endpoint 1 control clear register uecon1clr write-only 0x00000000 0x0228 endpoint 2 control clear register uecon2clr write-only 0x00000000 0x022c endpoint 3 control clear register uecon3clr write-only 0x00000000 0x0230 endpoint 4 control clear register uecon4clr write-only 0x00000000 0x0234 endpoint 5 control clear register uecon5clr write-only 0x00000000 0x0238 endpoint 6 control clear register uecon6clr write-only 0x00000000 0x023c endpoint 7 control clear register uecon7clr write-only 0x00000000 0x0310 device dma channel 1 next descriptor address register uddma1 nextdesc read/write 0x00000000 0x0314 device dma channel 1 hsb address register uddma1 addr read/write 0x00000000 0x0318 device dma channel 1 control register uddma1 control read/write 0x00000000 table 26-4. usbb register memory map offset register name access reset value
679 32072d?04/2011 at32uc3a3/a4 0x031c device dma channel 1 status register uddma1 status read/write 0x00000000 0x0320 device dma channel 2 next descriptor address register uddma2 nextdesc read/write 0x00000000 0x0324 device dma channel 2 hsb address register uddma2 addr read/write 0x00000000 0x0328 device dma channel 2 control register uddma2 control read/write 0x00000000 0x032c device dma channel 2 status register uddma2 status read/write 0x00000000 0x0330 device dma channel 3 next descriptor address register uddma3 nextdesc read/write 0x00000000 0x0334 device dma channel 3 hsb address register uddma3 addr read/write 0x00000000 0x0338 device dma channel 3 control register uddma3 control read/write 0x00000000 0x033c device dma channel 3 status register uddma3 status read/write 0x00000000 0x0340 device dma channel 4 next descriptor address register uddma4 nextdesc read/write 0x00000000 0x0344 device dma channel 4 hsb address register uddma4 addr read/write 0x00000000 0x0348 device dma channel 4 control register uddma4 control read/write 0x00000000 0x034c device dma channel 4 status register uddma4 status read/write 0x00000000 0x0350 device dma channel 5 next descriptor address register uddma5 nextdesc read/write 0x00000000 0x0354 device dma channel 5 hsb address register uddma5 addr read/write 0x00000000 0x0358 device dma channel 5 control register uddma5 control read/write 0x00000000 0x035c device dma channel 5 status register uddma5 status read/write 0x00000000 0x0360 device dma channel 6 next descriptor address register uddma6 nextdesc read/write 0x00000000 0x0364 device dma channel 6 hsb address register uddma6 addr read/write 0x00000000 0x0368 device dma channel 6 control register uddma6 control read/write 0x00000000 0x036c device dma channel 6 status register uddma6 status read/write 0x00000000 0x0370 device dma channel 7 next descriptor address register uddma7 nextdesc read/write 0x00000000 table 26-4. usbb register memory map offset register name access reset value
680 32072d?04/2011 at32uc3a3/a4 0x0374 device dma channel 7 hsb address register uddma7 addr read/write 0x00000000 0x0378 device dma channel 7 control register uddma7 control read/write 0x00000000 0x037c device dma channel 7status register uddma7 status read/write 0x00000000 0x0400 host general control register uhcon read/write 0x00000000 0x0404 host global interrupt register uhint read-only 0x00000000 0x0408 host global interrupt clear register uhintclr write-only 0x00000000 0x040c host global interrupt set register uhintset write-only 0x00000000 0x0410 host global interrupt enable register uhinte read-only 0x00000000 0x0414 host global interrupt enable cl ear register uhinteclr write-only 0x00000000 0x0418 host global interrupt enable set register uhinteset write-only 0x00000000 0x0041c pipe enable/reset register uprst read/write 0x00000000 0x0420 host frame number r egister uhfnum read/write 0x00000000 0x0424 host address 1 register uhaddr1 read/write 0x00000000 0x0428 host address 2 register uhaddr2 read/write 0x00000000 0x0500 pipe 0 configuration register upcfg0 read/write 0x00000000 0x0504 pipe 1 configuration register upcfg1 read/write 0x00000000 0x0508 pipe 2 configuration register upcfg2 read/write 0x00000000 0x050c pipe 3 configuration register upcfg3 read/write 0x00000000 0x0510 pipe 4 configuration register upcfg4 read/write 0x00000000 0x0514 pipe 5 configuration register upcfg5 read/write 0x00000000 0x0518 pipe 6 configuration register upcfg6 read/write 0x00000000 0x051c pipe 7 configuration register upcfg7 read/write 0x00000000 0x0530 pipe 0 status register upsta0 read-only 0x00000000 0x0534 pipe 1 status register upsta1 read-only 0x00000000 0x0538 pipe 2 status register upsta2 read-only 0x00000000 0x053c pipe 3 status register upsta3 read-only 0x00000000 0x0540 pipe 4 status register upsta4 read-only 0x00000000 0x0544 pipe 5 status register upsta5 read-only 0x00000000 0x0548 pipe 6 status register upsta6 read-only 0x00000000 0x054c pipe 7status register upsta7 read-only 0x00000000 0x0560 pipe 0 status clear register upsta0clr write-only 0x00000000 0x0564 pipe 1 status clear register upsta1clr write-only 0x00000000 0x0568 pipe 2 status clear register upsta2clr write-only 0x00000000 0x056c pipe 3 status clear register upsta3clr write-only 0x00000000 table 26-4. usbb register memory map offset register name access reset value
681 32072d?04/2011 at32uc3a3/a4 0x0570 pipe 4 status clear register upsta4clr write-only 0x00000000 0x0574 pipe 5 status clear register upsta5clr write-only 0x00000000 0x0578 pipe 6 status clear register upsta6clr write-only 0x00000000 0x057c pipe 7 status clear register upsta7clr write-only 0x00000000 0x0590 pipe 0 status set register upsta0set write-only 0x00000000 0x0594 pipe 1 status set register upsta1set write-only 0x00000000 0x0598 pipe 2 status set register upsta2set write-only 0x00000000 0x059c pipe 3 status set register upsta3set write-only 0x00000000 0x05a0 pipe 4 status set register upsta4set write-only 0x00000000 0x05a4 pipe 5 status set register upsta5set write-only 0x00000000 0x05a8 pipe 6 status set register upsta6set write-only 0x00000000 0x05ac pipe 7 status set register upsta7set write-only 0x00000000 0x05c0 pipe 0 control register upcon0 read-only 0x00000000 0x05c4 pipe 1 control register upcon1 read-only 0x00000000 0x05c8 pipe 2 control register upcon2 read-only 0x00000000 0x05cc pipe 3 control register upcon3 read-only 0x00000000 0x05d0 pipe 4 control register upcon4 read-only 0x00000000 0x05d4 pipe 5 control register upcon5 read-only 0x00000000 0x05d8 pipe 6 control register upcon6 read-only 0x00000000 0x05dc pipe 7 control register upcon7 read-only 0x00000000 0x05f0 pipe 0 control set register upcon0set write-only 0x00000000 0x05f4 pipe 1 control set register upcon1set write-only 0x00000000 0x05f8 pipe 2 control set register upcon2set write-only 0x00000000 0x05fc pipe 3 control set register upcon3set write-only 0x00000000 0x0600 pipe 4 control set register upcon4set write-only 0x00000000 0x0604 pipe 5 control set register upcon5set write-only 0x00000000 0x0608 pipe 6 control set register upcon6set write-only 0x00000000 0x060c pipe 7 control set register upcon7set write-only 0x00000000 0x0620 pipe 0 control clear register upcon0clr write-only 0x00000000 0x0624 pipe 1 control clear register upcon1clr write-only 0x00000000 0x0628 pipe 2 control clear register upcon2clr write-only 0x00000000 0x062c pipe 3 control clear register upcon3clr write-only 0x00000000 0x0630 pipe 4 control clear register upcon4clr write-only 0x00000000 0x0634 pipe 5 control clear register upcon5clr write-only 0x00000000 0x0638 pipe 6 control clear register upcon6clr write-only 0x00000000 0x063c pipe 7 control clear register upcon7clr write-only 0x00000000 table 26-4. usbb register memory map offset register name access reset value
682 32072d?04/2011 at32uc3a3/a4 0x0650 pipe 0 in request register upinrq0 read/write 0x00000000 0x0654 pipe 1 in request register upinrq1 read/write 0x00000000 0x0658 pipe 2 in request register upinrq2 read/write 0x00000000 0x065c pipe 3 in request register upinrq3 read/write 0x00000000 0x0660 pipe 4 in request register upinrq4 read/write 0x00000000 0x0664 pipe 5 in request register upinrq5 read/write 0x00000000 0x0668 pipe 6 in request register upinrq6 read/write 0x00000000 0x066c pipe 7 in request register upinrq7 read/write 0x00000000 0x0680 pipe 0 error register uperr0 read/write 0x00000000 0x0684 pipe 1 error register uperr1 read/write 0x00000000 0x0688 pipe 2 error register uperr2 read/write 0x00000000 0x068c pipe 3 error register uperr3 read/write 0x00000000 0x0690 pipe 4 error register uperr4 read/write 0x00000000 0x0694 pipe 5 error register uperr5 read/write 0x00000000 0x0698 pipe 6 error register uperr6 read/write 0x00000000 0x069c pipe 7 error register uperr7 read/write 0x00000000 0x0710 host dma channel 1 next descriptor address register uhdma1 nextdesc read/write 0x00000000 0x0714 host dma channel 1 hsb address register uhdma1 addr read/write 0x00000000 0x0718 host dma channel 1 control register uhdma1 control read/write 0x00000000 0x071c host dma channel 1 status register uhdma1 status read/write 0x00000000 0x0720 host dma channel 2 next descriptor address register uhdma2 nextdesc read/write 0x00000000 0x0724 host dma channel 2 hsb address register uhdma2 addr read/write 0x00000000 0x0728 host dma channel 2 control register uhdma2 control read/write 0x00000000 0x072c host dma channel 2 status register uhdma2 status read/write 0x00000000 0x0730 host dma channel 3 next descriptor address register uhdma3 nextdesc read/write 0x00000000 0x0734 host dma channel 3 hsb address register uhdma3 addr read/write 0x00000000 0x0738 host dma channel 3 control register uhdma3 control read/write 0x00000000 0x073c host dma channel 3status register uhdma3 status read/write 0x00000000 table 26-4. usbb register memory map offset register name access reset value
683 32072d?04/2011 at32uc3a3/a4 0x0740 host dma channel 4 next descriptor address register uhdma4 nextdesc read/write 0x00000000 0x0744 host dma channel 4 hsb address register uhdma4 addr read/write 0x00000000 0x0748 host dma channel 4 control register uhdma4 control read/write 0x00000000 0x074c host dma channel 4 status register uhdma4 status read/write 0x00000000 0x0750 host dma channel 5 next descriptor address register uhdma5 nextdesc read/write 0x00000000 0x0754 host dma channel 5 hsb address register uhdma5 addr read/write 0x00000000 0x0758 host dma channel 5 control register uhdma5 control read/write 0x00000000 0x075c host dma channel 5 status register uhdma5 status read/write 0x00000000 0x0760 host dma channel 6 next descriptor address register uhdma6 nextdesc read/write 0x00000000 0x0764 host dma channel 6 hsb address register uhdma6 addr read/write 0x00000000 0x0768 host dma channel 6 control register uhdma6 control read/write 0x00000000 0x076c host dma channel 6 status register uhdma6 status read/write 0x00000000 0x0770 host dma channel 7 next descriptor address register uhdma7 nextdesc read/write 0x00000000 0x0774 host dma channel 7 hsb address register uhdma7 addr read/write 0x00000000 0x0778 host dma channel 7 control register uhdma7 control read/write 0x00000000 0x077c host dma channel 7 status register uhdma7 status read/write 0x00000000 0x0800 general control register usbcon read/write 0x03004000 0x0804 general status regi ster usbsta read-only 0x00000400 0x0808 general status clear regi ster usbstaclr write-only 0x00000000 0x080c general status set regi ster usbstaset writ e-only 0x00000000 0x0818 ip version register uvers read-only - (1) 0x081c ip features register ufeatures read-only - (1) 0x0820 ip pb address size register uaddrsize read-only - (1) 0x0824 ip name register 1 uname1 read-only - (1) 0x0828 ip name register 2 uname2 read-only - (1) 0x082c usb finite state machine stat us register usbfsm read-only 0x00000009 table 26-4. usbb register memory map offset register name access reset value
684 32072d?04/2011 at32uc3a3/a4 note: 1. the reset values are device specific. please refer to the module configuration section at the end of this chapter. table 26-5. usb hsb memory map offset register name access reset value 0x00000 - 0x0fffc pipe/endpoint 0 fifo data register usb fifo0data read/write undefined 0x10000 - 0x1fffc pipe/endpoint 1 fifo data register usb fifo1data read/write undefined 0x20000 - 0x2fffc pipe/endpoint 2 fifo data register usb fifo2data read/write undefined 0x30000 - 0x3fffc pipe/endpoint 3 fifo data register usb fifo3data read/write undefined 0x40000 - 0x4fffc pipe/endpoint 4 fifo data register usb fifo4data read/write undefined 0x50000 - 0x5fffc pipe/endpoint 5 fifo data register usb fifo5data read/write undefined 0x60000 - 0x6fffc pipe/endpoint 6 fifo data register usb fifo6data read/write undefined 0x70000 - 0x7fffc pipe/endpoint 7 fifo data register usb fifo7data read/write undefined
685 32072d?04/2011 at32uc3a3/a4 26.8.1 usb general registers 26.8.1.1 general control register name: usbcon access type: read/write offset: 0x0800 reset value: 0x03004000 ? uimod: usbb mode this bit has no effect when uide is one (usb_id input pin activated). 0: the module is in usb host mode. 1: the module is in usb device mode. this bit can be written even if usbe is zero or frzclk is on e. disabling the usbb (by writing a zero to the usbe bit) does not reset this bit. ? uide: usb_id pin enable 0: the usb mode (device/host) is selected from the uimod bit. 1: the usb mode (device/host) is selected from the usb_id input pin. this bit can be written even if usbe is zero or frzclk is on e. disabling the usbb (by writing a zero to the usbe bit) does not reset this bit. ? unlock: timer access unlock 1: the timpage and timvalue fields are unlocked. 0: the timpage and timvalue fields are locked. the timpage and timvalue fields can alwa ys be read, whatever the value of unlock. ? timpage: timer page this field contains the page value to access a special timer register. ? timvalue: timer value this field selects the timer value that is written to the special time register selected by timpage. see section 26.7.1.8 for details. ? usbe: usbb enable writing a zero to this bit will reset the usbb, disable the usb transceiver and, disable the usbb clock inputs. unless explicit ly stated, all registers then will become read-only and will be reset. 1: the usbb is enabled. 0: the usbb is disabled. 31 30 29 28 27 26 25 24 ------uimoduide 23 22 21 20 19 18 17 16 - unlock timpage - - timvalue 15 14 13 12 11 10 9 8 usbe frzclk vbuspo otgpade vbushwc 76543210 stoe roleexe bcerre vberre vbuste idte
686 32072d?04/2011 at32uc3a3/a4 this bit can be written even if frzclk is one. ? frzclk: freeze usb clock 1: the clock input are disabled (the resume detection is still active).this reduces po wer consumption. unless explicitly stated , all registers then become read-only. 0: the clock inputs are enabled. this bit can be written even if usbe is ze ro. disabling the usbb (by writ ing a zero to the usbe bit) does not reset this bit, b ut this freezes the clock in puts whatever its value. ? vbuspo: vbus polarity 1: the usb_vbof output signal is inverted (active low). 0: the usb_vbof output signal is in its default mode (active high). to be generic. may be useful to control an external vbus power module. this bit can be written ev en if usbe is zero or frzclk is one. disabling the usbb (by writing a zero to the usbe bit) does not reset this bit. ? otgpade: otg pad enable 1: the otg pad is enabled. 0: the otg pad is disabled. this bit can be written ev en if usbe is zero or frzclk is one. disabling the usbb (by writing a zero to the usbe bit) does not reset this bit. ? vbushwc: vbus hardware control 1: the hardware control over t he usb_vbof output pin is disabled. 0: the hardware control over the usb_vbo f output pin is enabl ed. the usbb resets the usb_vb of output pin when a vbus problem occurs. ? stoe: suspend time-out interrupt enable 1: the suspend time-out interrupt (stoi) is enabled. 0: the suspend time-out interrupt (stoi) is disabled. ? roleexe: role exchange interrupt enable 1: the role exchange interrupt (roleexi) is enabled. 0: the role exchange interrupt (roleexi) is disabled. ? bcerre: b-connection error interrupt enable 1: the b-connection error interrupt (bcerri) is enabled. 0: the b-connection error interrupt (bcerri) is disabled. ? vberre: vbus error interrupt enable 1: the vbus error interrupt (vberri) is enabled. 0: the vbus error interrupt (vberri) is disabled. ? vbuste: vbus transition interrupt enable 1: the vbus transition interrupt (vbusti) is enabled. 0: the vbus transition interrupt (vbusti) is disabled. ? idte: id transition interrupt enable 1: the id transition interrupt (idti) is enabled. 0: the id transition interrupt (idti) is disabled.
687 32072d?04/2011 at32uc3a3/a4 26.8.1.2 general status register register name: usbsta access type: read-only offset: 0x0804 reset value: 0x00000400 ? clkusable: utmi clock usable this bit is set when the utmi 30mhz is usable. this bit is cleared when the utmi 30mhz is not usable. ? speed: speed status this field is set according to the controller speed mode. this field shall only be used in device mode. ? vbus: vbus level this bit is set when the vbus line level is high, even if usbe is zero. this bit is cleared when the vbus line level is low, even if usbe is zero. this bit can be used in device mode to monito r the usb bus connection state of the application. ? id: usb_id pin state this bit is cleared when the usb_id level is low, even if usbe is zero. this bit is set when the usb_id le vel is high, event if usbe is zero. ? vbusrq: vbus request this bit is set when the usbstaset .vbusrqs bit is written to one. this bit is cleared when the usbstaclr.vbusrqc bit is writte n to one or when a vbus error occurs and vbushwc is zero. 1: the usb_vbof output pin is driven high to enable the vbus power supply generation. 0: the usb_vbof output pin is driven low to disable the vbus power supply generation. this bit shall only be used in host mode. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - clkusable speed vbus id vbusrq - 76543210 stoi roleexi bcerri vberri vbusti idti speed speed status 0 0 full-speed mode 1 0 low-speed mode 0 1 high-speed mode 11reserved
688 32072d?04/2011 at32uc3a3/a4 ? stoi: suspend time-out interrupt this bit is set when a time-out error (more than 200ms) has b een detected after a suspend. this triggers a usb interrupt if stoe is one. this bit is cleared when the ubstaclr.stoic bit is written to one. this bit shall only be used in host mode. ? roleexi: role exchange interrupt this bit is set when the usbb has successfully switched its mode because of an negotiation (host to de vice or device to host). this triggers a usb interrupt if roleexe is one. this bit is cleared when the ubstaclr.roleexic bit is written to one. ? bcerri: b-connection error interrupt this bit is set when an error occurs during the b-conn ection. this triggers a usb interrupt if bcerre is one. this bit is cleared when the ubstaclr.bcerric bit is written to one. this bit shall only be used in host mode. ? vberri: vbus error interrupt this bit is set when a vbus drop has been detected. this triggers a usb interrupt if vberre is one. this bit is cleared when the ubstaclr.vberric bit is written to one. this bit shall only be used in host mode. if a vbus problem occurs, then the vberri interrupt is generat ed even if the usbb does not go to an error state because of vbushwc is one. ? vbusti: vbus transition interrupt this bit is set when a transition (high to low, low to high) has been detected on the usb_vbus pad. this triggers an usb interrupt if vbuste is one. this bit is cleared when the ubstaclr.vbustic bit is written to one. this interrupt is generated even if the clock is frozen by the frzclk bit. ? idti: id transition interrupt this bit is set when a transition (high to low, low to high) has been detected on the usb_id input pin. this triggers an usb interrupt if idte is one. this bit is cleared when the ubst aclr.idtic bit is written to one. this interrupt is generated even if the clock is frozen by the frzclk bit.
689 32072d?04/2011 at32uc3a3/a4 26.8.1.3 general status clear register register name: usbstaclr access type: write-only offset: 0x0808 read value: 0x00000000 writing a one to a bit in this register will clear the corresponding bit in ubsta. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 ------vbusrqc- 76543210 stoic roleexic bcerric vberric vbustic idtic
690 32072d?04/2011 at32uc3a3/a4 26.8.1.4 general status set register register name: usbstaset access type: write-only offset: 0x080c read value: 0x00000000 writing a one to a bit in this register will set the corresponding bit in ubsta, what may be useful for test or debug purposes. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 ------vbusrqs- 76543210 stois roleexis bcerris vberris vbustis idtis
691 32072d?04/2011 at32uc3a3/a4 26.8.1.5 version register register name: uvers access type: read-only offset: 0x0818 read value: - ? variant: variant number reserved. no functionality associated. ? version: version number version number of the module. no functionality associated. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ---- variant 15 14 13 12 11 10 9 8 - - - - version[11:8] 76543210 version[7:0]
692 32072d?04/2011 at32uc3a3/a4 26.8.1.6 features register register name: ufeatures access type: read-only offset: 0x081c read value: - ? enhbison: high bandwidth isoc hronous feature for endpoint n 1: the high bandwidth isochronous is supported. 1: the high bandwidth isochronous is not supported. ? databus: data bus 16-8 1: the utmi data bus is a 16-bit data path at 30mhz. 0: the utmi data bus is a 8-bit data path at 60mhz. ? bytewritedpram: dpram byte-write capability 1: the dpram is natively byte-write capable. 0: the dpram byte write lanes have shadow logic implemented in the usbb ip interface. ? fifomaxsize: maximal fifo size this field indicates the maximal fifo size, i.e., the dpram size: 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 enhbiso7 enhbiso6 enhbiso5 enhbiso4 enhbiso3 enhbiso2 enhbiso1 databus 15 14 13 12 11 10 9 8 bytewrite dpram fifomaxsize dmaf ifoworddepth 76543210 dmabuffe rsize dmachannelnbr eptnbrmax fifomaxsize maximal fifo size 0 0 0 < 256 bytes 0 0 1 < 512 bytes 0 1 0 < 1024 bytes 0 1 1 < 2048 bytes 1 0 0 < 4096 bytes 1 0 1 < 8192 bytes 1 1 0 < 16384 bytes 1 1 1 >= 16384 bytes
693 32072d?04/2011 at32uc3a3/a4 ? dmafifoworddepth: dma fifo depth in words this field indicates the dma fifo depth controller in words: ? dmabuffersize: dma buffer size 1: the dma buffer size is 24bits. 0: the dma buffer size is 16bits. ? dmachannelnbr: number of dma channels this field indicates the number of hardware-implemented dma channels: ? eptnbrmax: maximal number of pipes/endpoints this field indicates the number of hardware-implemented pipes/endpoints: dmafifoworddepth dma fifo depth in words 000016 00011 00102 ... 111115 dmachannelnbr number of dma channels 000reserved 0011 0102 ... 1117 eptnbrmax maximal number of pipes/endpoints 000016 00011 00102 ... 111115
694 32072d?04/2011 at32uc3a3/a4 26.8.1.7 address size register register name: uaddrsize access type: read-only offset: 0x0820 read value: - ? uaddrsize: ip pb address size this field indicates the size of the pb address space reserved for the usbb ip interface. 31 30 29 28 27 26 25 24 uaddrsize[31:24] 23 22 21 20 19 18 17 16 uaddrsize[23:16] 15 14 13 12 11 10 9 8 uaddrsize[15:8] 76543210 uaddrsize[7:0]
695 32072d?04/2011 at32uc3a3/a4 26.8.1.8 name register 1 register name: uname1 access type: read-only offset: 0x0824 read value: - ? uname1: ip name part one this field indicates the first part of the ascii-encoded name of the usbb ip. 31 30 29 28 27 26 25 24 uname1[31:24] 23 22 21 20 19 18 17 16 uname1[23:16] 15 14 13 12 11 10 9 8 uname1[15:8] 76543210 uname1[7:0]
696 32072d?04/2011 at32uc3a3/a4 26.8.1.9 name register 2 register name: uname2 access type: read-only offset: 0x0828 read value: ? uname2: ip name part two this field indicates the second part of the ascii-encoded name of the usbb ip. 31 30 29 28 27 26 25 24 uname2[31:24] 23 22 21 20 19 18 17 16 uname2[23:16] 15 14 13 12 11 10 9 8 uname2[15:8] 76543210 uname2[7:0]
697 32072d?04/2011 at32uc3a3/a4 26.8.1.10 finite state machine status register register name: usbfsm access type: read-only offset: 0x082c read value: 0x00000009 ? drdstate this field indicates the state of the usbb. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - - - drdstate drdstate description 0 a_idle state: this is the start state for a-devices (when the id pin is 0) 1 a_wait_vrise: in this state, the a-device wa its for the voltage on vbus to rise above the a- device vbus valid threshold (4.4 v). 2 a_wait_bcon: in this state, the a-device waits for the b-device to signal a connection. 3 a_host: in this state, the a-device that operates in host mode is operational. 4 a_suspend: the a-device operating as a host is in the suspend mode. 5 a_peripheral: the a-device operates as a peripheral. 6 a_wait_vfall: in this state, the a-device wa its for the voltage on vbus to drop below the a- device session valid threshold (1.4 v). 7 a_vbus_err: in this state, the a-device waits for recovery of the over-current condition that caused it to enter this state. 8 a_wait_discharge: in this state, the a-device waits for the data usb line to discharge (100 us). 9 b_idle: this is the start state for b-device (when the id pin is 1). 10 b_peripheral: in this state, the b-device acts as the peripheral. 11 b_wait_begin_hnp: in this state, the b-device is in suspend mode and waits until 3 ms before initiating the hnp protocol if requested. 12 b_wait_discharge: in this state, the b-device waits for the data usb line to discharge (100 us) before becoming host.
698 32072d?04/2011 at32uc3a3/a4 13 b_wait_acon: in this state, the b-device wait s for the a-device to signal a connect before becoming b-host. 14 b_host: in this state, the b-device acts as the host. 15 b_srp_init: in this state, the b-device attempts to start a session using the srp protocol. drdstate description
699 32072d?04/2011 at32uc3a3/a4 26.8.2 usb device registers 26.8.2.1 device genera l control register register name: udcon access type: read/write offset: 0x0000 reset value: 0x00000100 ? opmode2: specific operational mode 1: the utmi transceiver is in the ?disable bit stuffing and nrzi encoding? operational mode for test purpose. 0: the utmi transceiver is in normal operation mode. ? tstpckt: test packet mode 1: the utmi transceiver generates test packets for test purpose. 0: the utmi transceiver is in normal operation mode. ?tstk: test mode k 1: the utmi transceiver generates high-speed k state for test purpose. 0: the utmi transceiver is in normal operation mode. ? tstj: test mode j 1: the utmi transceiver generates high-speed j state for test purpose. 0: the utmi transceiver is in normal operation mode. ? ls: low-speed mode force 1: the low-speed mode is active. 0: the full-speed mode is active. this bit can be written even if usbe is zero or frzclk is on e. disabling the usbb (by writing a zero to the usbe bit) does not reset this bit. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------opmode2 15 14 13 12 11 10 9 8 tstpckt tstk tstj ls spdconf rmwkup detach 76543210 adden uadd
700 32072d?04/2011 at32uc3a3/a4 ? spdconf: speed configuration this field contains the peripheral speed. ? rmwkup: remote wake-up writing a one to this bit will send an upstream resume to the host for a remote wake-up. writing a zero to this bit has no effect. this bit is cleared when the usbb receive a usb reset or once the upstream resume has been sent. ? detach: detach writing a one to this bit will physically detach the device (disconnect internal pull-up resistor from d+ and d-). writing a zero to this bit will reconnect the device. ? adden: address enable writing a one to this bit will activate the uadd field (usb address). writing a zero to this bit has no effect. this bit is cleared when a usb reset is received. ? uadd: usb address this field contains the device address. this field is cleared when a usb reset is received. spdconf speed 00 normal mode: the peripheral starts in full-speed mode and performs a high-speed reset to switch to the high-speed mode if the host is high-speed capable. 0 1 reserved, do not use this configuration 1 0 reserved, do not use this configuration 1 1 full-speed: the peripheral remains in full-spe ed mode whatever is the host speed capability.
701 32072d?04/2011 at32uc3a3/a4 26.8.2.2 device global interrupt register register name: udint access type: read-only offset: 0x0004 reset value: 0x00000000 ? dmanint: dma channel n interrupt this bit is set when an interrupt is triggered by the dma channel n. this triggers a usb interrupt if dmaninte is one. this bit is cleared when the uddmanstatus interrupt source is cleared. ? epnint: endpoint n interrupt this bit is set when an interrupt is triggered by the endpoint n (uestan, ueconn). this triggers a usb interrupt if epninte is one. this bit is cleared when the interrupt source is serviced. ? uprsm: upstream resume interrupt this bit is set when the usbb sends a resume signal called ?ups tream resume?. this triggers a usb interrupt if uprsme is one. this bit is cleared when the udintclr.uprsmc bit is written to one to acknowledge the interrupt (usb clock inputs must be enabled before). ? eorsm: end of resume interrupt this bit is set when the usbb detects a valid ?end of resume? si gnal initiated by the host. th is triggers a usb interrupt if eorsme is one. this bit is cleared when the udintclr.eorsmc bit is written to one to acknowledge the interrupt. ? wakeup: wake-up interrupt this bit is set when the usbb is reactivated by a filtered non- idle signal from the lines (not by an upstream resume). this triggers an interrupt if wakeupe is one. this bit is cleared when the udintclr.wakeupc bit is written to one to acknowledge the interrupt (usb clock inputs must be enabled before). this bit is cleared when the suspend (susp) interrupt bit is set. this interrupt is generated even if the clock is frozen by the frzclk bit. ? eorst: end of reset interrupt this bit is set when a usb ?end of reset? has been dete cted. this triggers a usb interrupt if eorste is one. this bit is cleared when the udintclr.eorstc bit is written to one to acknowledge the interrupt. 31 30 29 28 27 26 25 24 dma7int dma6int dma5int dma4int dma3int dma2int dma1int - 23 22 21 20 19 18 17 16 - - - - ep7int ep6int ep5int ep4int 15 14 13 12 11 10 9 8 ep3int ep2int ep1int ep0int - - - - 76543210 - uprsm eorsm wakeup eorst sof msof susp
702 32072d?04/2011 at32uc3a3/a4 ? sof: start of frame interrupt this bit is set when a usb ?start of frame? pid (sof) has been de tected (every 1 ms). this triggers a usb interrupt if sofe is one. the fnum field is updated. in high- speed mode, the mfnum field is cleared. this bit is cleared when the udintclr.sofc bit is written to one to acknowledge the interrupt. ? msof: micro start of frame interrupt this bit is set in high-speed mode when a usb ?micro start of frame? pid (sof) has been detected (every 125 us). this triggers a usb interrupt if msofe is one. the mfnum field is updated. the fnum field is unchanged. this bit is cleared when the udintclr.msofc bit is written to one to acknowledge the interrupt. ? susp: suspend interrupt this bit is set when a usb ?suspend? idle bus state has been det ected for 3 frame periods (j stat e for 3 ms). this triggers a usb interrupt if suspe is one. this bit is cleared when the udintclr.suspc bit is written to one to acknowledge the interrupt. this bit is cleared when the wake-up (wakeup) interrupt bit is set.
703 32072d?04/2011 at32uc3a3/a4 26.8.2.3 device global interrupt clear register register name: udintclr access type: write-only offset: 0x0008 read value: 0x00000000 writing a one to a bit in this register will clear the corresponding bit in udint. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - uprsmc eorsmc wakeupc eorstc sofc msofc suspc
704 32072d?04/2011 at32uc3a3/a4 26.8.2.4 device global interrupt set register register name: udintset access type: write-only offset: 0x000c read value: 0x00000000 writing a one to a bit in this register will set the correspondin g bit in udint, what may be useful for test or debug purposes. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 dma7ints dma6ints dma5ints dma4ints dma3ints dma2ints dma1ints - 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - uprsms eorsms wakeups eorsts sofs msofs susps
705 32072d?04/2011 at32uc3a3/a4 26.8.2.5 device global interrupt enable register register name: udinte access type: read-only offset: 0x0010 reset value: 0x00000000 1: the corresponding interrupt is enabled. 0: the corresponding interrupt is disabled. a bit in this register is set when the corresponding bit in udinteset is written to one. a bit in this register is cleared when the corresponding bit in udinteclr is written to one. 31 30 29 28 27 26 25 24 dma7inte dma6inte dma5inte dma4inte dma3inte dma2inte dma1inte - 23 22 21 20 19 18 17 16 - - - - ep7inte ep6inte ep5inte ep4inte 15 14 13 12 11 10 9 8 ep3inte ep2inte ep1inte ep0inte - - - - 76543210 - uprsme eorsme wakeupe eorste sofe msofe suspe
706 32072d?04/2011 at32uc3a3/a4 26.8.2.6 device global interrupt enable clear register register name: udinteclr access type: write-only offset: 0x0014 read value: 0x00000000 writing a one to a bit in this register will clear the corresponding bit in udinte. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 dma7intec dma6intec dma5intec dma4i ntec dma3intec dma2intec dma1intec - 23 22 21 20 19 18 17 16 - - - - ep7intec ep6intec ep5intec ep4intec 15 14 13 12 11 10 9 8 ep3intec ep2intec ep1intec ep0intec - - - - 76543210 - uprsmec eorsmec wakeupec eorstec sofec msofec suspec
707 32072d?04/2011 at32uc3a3/a4 26.8.2.7 device global interrupt enable set register register name: udinteset access type: write-only offset: 0x0018 read value: 0x00000000 writing a one to a bit in this register will set the corresponding bit in udinte. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 dma7intes dma6intes dma5intes dma4i ntes dma3intes dma2intes dma1intes - 23 22 21 20 19 18 17 16 - - - - ep7intes ep6intes ep5intes ep4intes 15 14 13 12 11 10 9 8 ep3intes ep2intes ep1intes ep0intes - - - - 76543210 - uprsmes eorsmes wakeupes eorstes sofes msofes suspes
708 32072d?04/2011 at32uc3a3/a4 26.8.2.8 endpoint enable/reset register register name: uerst access type: read/write offset: 0x001c reset value: 0x00000000 ? eprstn: endpoint n reset writing a one to this bit will reset the endpoint n fifo prior to any other operation, upon hardware reset or when a usb bus reset has been received. this resets the endpoint n registers (uecfgn, uestan, ueconn) but not the endpoint configuration (alloc, epbk, epsize, epdir, eptype). all the endpoint mechanism (fifo counter, reception, transmission, etc.) is reset apart from the data toggle sequence field (dtseq) which can be cleared by setting the rstdt bit (by writing a one to the rstdts bit). the endpoint configuration remains active and the endpoint is still enabled. writing a zero to this bit will complete the reset operation and start using the fifo. this bit is cleared upon receiving a usb reset. ? epenn: endpoint n enable 1: the endpoint n is enabled. 0: the endpoint n is disabled, what forces the endpoint n state to inactive (no answ er to usb requests) and resets the endpoint n registers (uecfgn, uestan, ueconn ) but not the endpoi nt configuration (alloc, epbk, epsize, epdir, eptype). 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 eprst7 eprst6 eprst5 eprst4 eprst3 eprst2 eprst1 eprst0 15 14 13 12 11 10 9 8 -------- 76543210 epen7 epen6 epen5 epen4 epen3 epen2 epen1 epen0
709 32072d?04/2011 at32uc3a3/a4 26.8.2.9 device frame number register register name: udfnum access type: read-only offset: 0x0020 reset value: 0x00000000 ? fncerr: frame number crc error this bit is set when a corrupted frame number (or micro-frame nu mber) is received. this bit and the sof (or msof) interrupt bit are updated at the same time. this bit is cleared upon receiving a usb reset. ? fnum: frame number this field contains the 11-bit fram e number information. it is provided in the last received sof packet. this field is cleared upon receiving a usb reset. fnum is updated even if a corrupted sof is received. ? mfnum: micro frame number this field contains the 3-bit micro frame number inform ation. it is provided in the last received msof packet. this field is cleared at the beginning of each start of frame (sof interrupt) or upon receiving a usb reset. mfnum is updated even if a co rrupted msof is received. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 fncerr - fnum[10:5] 76543210 fnum[4:0] mfnum
710 32072d?04/2011 at32uc3a3/a4 26.8.2.10 endpoint n configuration register register name: uecfgn, n in [0..7] access type: read/write offset: 0x0100 + (n * 0x04) reset value: 0x00000000 ? nbtrans: number of transaction per microframe for is ochronous endpoint this field shall be written to the number of transaction per microframe to perform high-bandwidth isochronous transfer this field can be written only for endpoint that have this capa bility (see ufeatures register, enhbison bit). this field is 0 otherwise. this field is irrelevant for non-isochronous endpoint. look at the ufeatures register to know if the high-bandwidth isochronous feature is supported by the device. . ? eptype: endpoint type this field shall be written to select the endpoint type: this field is cleared upon receiving a usb reset. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - nbtrans eptype - autosw epdir 76543210 - epsize epbk alloc - nbtrans number of transaction 0 0 reserved to endpoint that does not have the high-bandwidth isochronous capability. 0 1 default value: one transaction per micro-frame. 1 0 2 transactions per micro-frame. this endpoint should be configured as double-bank. 11 3 transactions per micro-frame. this endpoint should be configured as triple-bank if supported (see table 26-1 on page 636 ) . eptype endpoint type 0 0 control 0 1 isochronous 10bulk 1 1 interrupt
711 32072d?04/2011 at32uc3a3/a4 ? autosw: automatic switch this bit is cleared upon receiving a usb reset. 1: the automatic bank switching is enabled. 0: the automatic bank switching is disabled. ? epdir: endpoint direction this bit is cleared upon receiving a usb reset. 1: the endpoint direction is in (nor for control endpoints). 0: the endpoint direction is out. ? epsize: endpoint size this field shall be written to select the size of each endpoint bank. the maximum size of each endpoint is specified in table 26- 1 on page 636 . this field is cleared upon receiving a usb reset (except for the endpoint 0). ? epbk: endpoint banks this field shall be written to select the number of banks for the endpoint: for control endpoints, a single-bank en dpoint (0b00) shall be selected. this field is cleared upon receiving a usb reset (except for the endpoint 0). ? alloc: endpoint memory allocate writing a one to this bit will allocate the endpoint memory. the user should check the cfgok bit to know whether the allocation of this endpoint is correct. writing a zero to this bit will free the endpoint memory. this bit is cleared upon receiving a usb reset (except for the endpoint 0). epsize endpoint size 0 0 0 8 bytes 00116 bytes 01032 bytes 01164 bytes 1 0 0 128 bytes 1 0 1 256 bytes 1 1 0 512 bytes epbk endpoint banks 0 0 1 (single-bank endpoint) 0 1 2 (double-bank endpoint) 1 0 3 (triple-bank endpoint) if supported (see table 26-1 on page 636 ). 11reserved
712 32072d?04/2011 at32uc3a3/a4 26.8.2.11 endpoint n status register register name: uestan, n in [0..7] access type: read-only 0x0100 offset: 0x0130 + (n * 0x04) reset value: 0x00000100 ?byct: byte count this field is set with the byte count of the fifo. for in endpoints, incremented after each byte written by the software into the endpoi nt and decremented afte r each byte sent to the host. for out endpoints, incremented after each byte received from th e host and decremented after each byte read by the software from the endpoint. this field may be updated one clock cycle after the rwall bit changes, so the user should not poll this field as an interrupt b it. ? cfgok: configuration ok status this bit is updated when the alloc bit is written to one. this bit is set if the endpoint n number of banks (epbk) an d size (epsize) are correct compared to the maximal allowed number of banks and size for this endpoint and to the maximal fifo size (i.e. the dpram size). if this bit is cleared, the user shall rewrite correct va lues to the epbk and epsize fiel ds in the uecfgn register. ? ctrldir: control direction this bit is set after a setup packet to indica te that the following packet is an in packet. this bit is cleared after a setup packet to indicate that the following packet is an out packet. writing a zero or a one to this bit has no effect. ? rwall: read/write allowed this bit is set for in endpoints when the current bank is not full, i.e., the user can write further data into the fifo. this bit is set for out endpoints when the current bank is no t empty, i.e., the user can read further data from the fifo. this bit is never set if stallrq is one or in case of error. this bit is cleared otherwise. this bit shall not be used for control endpoints. 31 30 29 28 27 26 25 24 - byct 23 22 21 20 19 18 17 16 byct - cfgok ctrldir rwall 15 14 13 12 11 10 9 8 currbk nbusybk - errortrans dtseq 76543210 short packet stalledi/ crcerri overfi nakini/ hbisoflushi nakouti/ hbisoinerri rxstpi/ underfi rxouti txini
713 32072d?04/2011 at32uc3a3/a4 ? currbk: current bank this bit is set for non-control endpoints, to indicate the current bank: this field may be updated one clock cycle after the rwall bit changes, so the user should not poll this field as an interrupt b it. ? nbusybk: number of busy banks this field is set to indicate the number of busy banks: for in endpoints, it indicates the number of banks filled by t he user and ready for in transfer. when all banks are free, this triggers an epnint interrupt if nbusybke is one. for out endpoints, it indicates the number of banks filled by ou t transactions from the host. when all banks are busy, this triggers an epnint interrupt if nbusybke is one. when the fifocon bit is cleared (by writin g a one to the fifoconc bit) to validate a new bank, this field is updated two or three clock cycles later to calcul ate the address of the next bank. an epnint interrupt is triggered if: - for in endpoint, nbusybke is o ne and all the banks are free. - for out endpoint, nbusybke is one and all the banks are busy. ? errortrans: high-bandwidth isochronous out endpoint transaction error interrupt this bit is set when a transaction error occurs during the curr ent micro-frame (the data toggle sequencing does not respect the usb 2.0 standard). this triggers an epnint interrupt if errortranse is one. this bit is set as long as the current bank (currbk) belongs to the bad n-transactions (n=1,2 or 3) transferred during the micro-frame. shall be cleared by software by clearing (at least once) the fifocon bit to switch to the bank that belongs to the next n-transactions (next micro-frame). look at the ufeatures register to know if the high-ban dwidth isochronous feature is supported by the device. ? dtseq: data toggle sequence this field is set to indicate the pid of the current bank: for in transfers, it indicates the data t oggle sequence that will be used for the next packet to be sent. this is not relative to the current bank. currbk current bank 00bank0 01bank1 1 0 bank2 if supported (see table 26-1 on page 636 ). 11reserved nbusybk number of busy banks 0 0 0 (all banks free) 011 102 1 1 3 if supported (see table 26-1 on page 636 ). dtseq data toggle sequence 00data0 01data1 1 0 data2 (for high-bandwidth isochronous endpoint) 1 1 mdata (for high-bandwidth isochronous endpoint)
714 32072d?04/2011 at32uc3a3/a4 for out transfers, this value indicates the last data toggle sequence received on the current bank. by default dtseq is 0b01, as if the last data toggle sequence was data1, so the next sent or expected data toggle sequence should be data0. for high-bandwidth isochronous endpoint, an epnint interrupt is triggered if: - mdatae is one and a mdata packet has been received (dtseq=mdata and rxouti is one). - dataxe is one and a data0/1/2 packet has been received (dtseq =data0/1/2 and rxouti is one) look at the ufeatures register to know if the high-ban dwidth isochronous feature is supported by the device. ? shortpacket: short packet interrupt this bit is set for non-control out endpoints, when a short packet has been received. this bit is set for non-control in endpoints, a short packet is transmitted upon ending a dma transfer, thus signaling an end o f isochronous frame or a bulk or interrupt end of transfer, this only if the end of dma buffer output enable (dmaenden) bit and the automatic switch (autosw) bit are written to one. this triggers an epnint interrupt if shortpackete is one. this bit is cleared when the shortpacketc bit is written to one. this will acknowledge the interrupt. ? stalledi: stalled interrupt this bit is set to signal that a stall handshake has been sent . to do that, the software has to set the stallrq bit (by writing a one to the stallrqs bit). this triggers an epnint interrupt if stallede is one. this bit is cleared when the stalledic bit is written to one. this will acknowledge the interrupt. ? crcerri: crc error interrupt this bit is set to signal that a crc error has been detected in an isochronous out endpoint. the out packet is stored in the bank as if no crc error had occurred. this trig gers an epnint interrupt if crcerre is one. this bit is cleared when the crcerric bit is written to one. this will acknowledge the interrupt. ? overfi: overflow interrupt this bit is set when an overflow error occurs. this triggers an epn int interrupt if overfe is one. for all endpoint types, an overflow can occur during out stage if th e host attempts to write into a bank that is too small for the packet. the packet is acknowledged and the rxouti bit is set as if no overflow had occurred. the bank is filled with all the fi rst bytes of the packet that fit in. this bit is cleared when the overfic bit is written to one. this will acknowledge the interrupt. ? nakini: naked in interrupt this bit is set when a nak handshake has been sent in response to an in request from the host. this triggers an epnint interrupt if nakine is one. this bit is cleared when the nakinic bit is writ ten to one. this will acknowledge the interrupt. ? hbisoflushi: high bandwidth isochronous in flush interrupt this bit is set, for high-bandwidth isochronous in endpoint (wit h nbtrans=2 or 3), at the end of the micro-frame, if less than n transaction has been completed by the usbb without underflow error. this may occur in case of a missing in token. in this case, the bank are flushed out to ensure the data synchroniza tion between the host and the device. this triggers an epnint interrupt if hbisoflushe is one. this bit is cleared when the hbisoflushic bit is written to one. this will acknowledge the interrupt. look at the ufeatures register to know if the high-ban dwidth isochronous feature is supported by the device. ? nakouti: naked out interrupt this bit is set when a nak handshake has been sent in response to an out request from the host. this triggers an epnint interrupt if nakoute is one. this bit is cleared when the nakoutic bit is written to one. this will acknowledge the interrupt. ? hbisoinerri: high bandwidth isochronous in underflow error interrupt this bit is set, for high-bandwidth isochronous in endpoint (with nbtrans=2 or 3), at the end of the microframe, if less than n bank was written by the cpu within this micro-frame. this triggers an epn int interrupt if hbisoinerre is one. this bit is cleared when the hbisoinerric bit is written to one. this will acknowledge the interrupt. look at the ufeatures register to know if the high-ban dwidth isochronous feature is supported by the device. ? underfi: underflow interrupt this bit is set, for isochronous in/out endpoints, when an underflow error occurs. this triggers an epnint interrupt if underfe is one.
715 32072d?04/2011 at32uc3a3/a4 an underflow can occur during in stage if the host attempts to read from an empty bank. a zero-length packet is then automatically sent by the usbb. an underflow can also occur duri ng out stage if the host sends a packet while th e bank is already full. typically, the cpu is n ot fast enough. the packet is lost. shall be cleared by writing a one to the underfic bit. this will acknowledge the interrupt. this bit is inactive (cleared) for bulk and interrupt in/out endpoints and it means rxstpi for control endpoints. ? rxstpi: received setup interrupt this bit is set, for control endpoints, to signal that the curre nt bank contains a new valid setup packet. this triggers an epn int interrupt if rxstpe is one. shall be cleared by writing a one to the rxstpic bit. this will acknowledge the interrupt and free the bank. this bit is inactive (cleared) for bulk and interrupt in/out endpoints and it means underfi for isochronous in/out endpoints. ? rxouti: received out data interrupt this bit is set, for control endpoints, when the current bank c ontains a bulk out packet (data or status stage). this triggers an epnint interrupt if rxoute is one. shall be cleared for control end points, by writing a one to th e rxoutic bit. this will acknowledge the interrupt and free the bank. this bit is set for isochronous, bulk and, interrupt out endpoints, at the same time as fifocon when the current bank is full. this triggers an epnint interrupt if rxoute is one. shall be cleared for isochronous, bulk and, interrupt out endpo ints, by writing a one to the rxoutic bit. this will acknowledge the interrupt, what has no effect on the endpoint fifo. the user then reads from the fifo and cl ears the fifocon bit to free the bank. if the out endpoint is composed of multiple banks, this also switches to the next b ank. the rxouti and fifocon bits are set/clea red in accordance with the status of the next bank. rxouti shall always be cleared before clearing fifocon. this bit is inactive (cleared) for isochronous, bulk and interrupt in endpoints. ? txini: transmitted in data interrupt this bit is set for control endpoints, when the current bank is ready to accept a new in packet. this triggers an epnint interr upt if txine is one. this bit is cleared when the txinic bit is written to on e. this will acknowledge the interrupt and send the packet. this bit is set for isochronous, bulk and interrupt in endpoints, at the same time as fifocon when the current bank is free. this triggers an epnint interrupt if txine is one. this bit is cleared when the txinic bit is written to one. th is will acknowledge the interrupt, what has no effect on the endpo int fifo. the user then writes into the fifo and cl ears the fifocon bit to allow the usbb to send the data. if the in endpoint is composed of multiple banks, this also switches to the next bank. the txini and fi focon bits are set/cleared in accordance with the status of the next bank. txini shall always be cleared before clearing fifocon. this bit is inactive (cleared) for isochronous, bulk and interrupt out endpoints.
716 32072d?04/2011 at32uc3a3/a4 26.8.2.12 endpoint n status clear register register name: uestanclr, n in [0..7] access type: write-only offset: 0x0160 + (n * 0x04) read value: 0x00000000 writing a one to a bit in this register will clear the corresponding bit in uesta. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 short packetc stalledic/ crcerric overfic nakinic/ hbisoflushic nakoutic/ hbisoinerric rxstpic/ underfic rxoutic txinic
717 32072d?04/2011 at32uc3a3/a4 26.8.2.13 endpoint n status set register register name: uestanset, n in [0..7] access type: write-only offset: 0x0190 + (n * 0x04) read value: 0x00000000 writing a one to a bit in this register will set the correspondin g bit in uesta, what may be useful for test or debug purposes. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - nbusybks - - - 76543210 short packets stalledis/ crcerris overfis nakinis/ hbisoflushis nakoutis/ hbisoinerris rxstpis/ underfis rxoutis txinis
718 32072d?04/2011 at32uc3a3/a4 26.8.2.14 endpoint n control register register name: ueconn, n in [0..7] access type: read-only offset: 0x01c0 + (n * 0x04) reset value: 0x00000000 ? stallrq: stall request this bit is set when the stallrqs bit is written to one. this will request to send a stall handshake to the host. this bit is cleared when a new setup packet is received or when the stallrqc bit is written to zero. ? rstdt: reset data toggle this bit is set when the rstdts bit is written to one. this will clear the data toggle sequence, i.e., set to data0 the data to ggle sequence of the next sent (in endpoints) or received (out endpoints) packet. this bit is cleared instantaneously. the user does not have to wait for this bit to be cleared. ? nyetdis: nyet token disable this bit is set when the nyetdiss bit is written to one. this will send a ack handshake instead of a nyet handshake in high- speed mode. this bit is cleared when the nyetdisc bit is written to one. this will let the usbb handling the high-speed handshake following the usb 2.0 standard. ? epdishdma: endpoint interrupts disable hdma request enable this bit is set when the epdishdmas is written to one. this w ill pause the on-going dma channel n transfer on any endpoint n interrupt (epnint), whatever the state of th e endpoint n interrupt enable bit (epninte). the user then has to acknowledge or to disable the interrupt so urce (e.g. rxouti) or to clear the epdishdma bit (by writing a one to the epdishdmac bit) in order to complete the dma transfer. in ping-pong mode, if the interrupt is associated to a new system-bank packet (e.g. bank1) and the current dma transfer is running on the previous packet (bank0), then the previous-packet dma transfer completes normally, but the new-packet dma transfer will not start (not requested). if the interrupt is not associated to a new system-bank pack et (nakini, nakouti, etc.), then the request cancellation may occur at any time and may immediately pause the current dma transfer. this may be used for example to identify erroneous packets, to prevent them from being transferred into a buffer, to complete a dma transfer by software after reception of a short packet, etc. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - stallrq rstdt nyetdis epdishdma 15 14 13 12 11 10 9 8 - fifocon killbk nbusybke - errortranse dataxe mdatae 76543210 short packete stallede/ crcerre overfe nakine/ hbisoflushe nakoute/ hbisoinerre rxstpe/ underfe rxoute txine
719 32072d?04/2011 at32uc3a3/a4 ? fifocon: fifo control for control endpoints: the fifocon and rwall bits are irrelevant. the software shal l therefore never use them on these endpoints. when read, their value is always 0. for in endpoints: this bit is set when the current bank is free, at the same time as txini. this bit is cleared (by writing a one to the fifoconc bit) to send the fifo data and to switch to the next bank. for out endpoints: this bit is set when the current bank is full, at the same time as rxouti. this bit is cleared (by writing a one to the fifoconc bit) to free the current bank and to switch to the next bank. ? killbk: kill in bank this bit is set when the killbks bit is written to one. this will kill the last written bank. this bit is cleared by hardware after the completion of the ?kill packet procedure?. the user shall wait for this bit to be cleared before trying to process another in packet. caution: the bank is cl eared when the ?ki ll packet? procedure is completed by the usbb core : if the bank is really killed, the nbusybk field is decremented. if the bank is not ?killed? but sent (in transfer), the nbusybk fi eld is decremented and the txini flag is set. this specific c ase can occur if at the same time an in token is coming and the user wants to kill this bank. note : if two banks are ready to be sent, the above specific case can not occur, because the first bank is sent (in transfer) w hile the last bank is killed. ? nbusybke: number of bu sy banks interrupt enable this bit is set when the nbusybkes bit is written to one. this will enable the number of busy banks interrupt (nbusybk). this bit is cleared when the nbusybkec bi t is written to zero. this will disabl e the number of busy banks interrupt (nbusybk). ? errortranse: transaction error interrupt enable this bit is set when the errortranses bit is written to one. this will enable the transaction error interrupt (errortrans). this bit is cleared when the errortransec bit is written to one. this will disable the transaction error interrupt (errortrans). ? dataxe: datax interrupt enable this bit is set when the dataxes bit is written to one. this will enable the datax in terrupt. (see dtseq bits) this bit is cleared when the dataxec bit is written to one. this will disable the datax interrupt. ? mdatae: mdata interrupt enable this bit is set when the mdataes bit is written to one. this will enable the multiple data interrupt. (see dtseq bits) this bit is cleared when the mdataec bit is written to one. this will disable the multiple data interrupt. ? shortpackete: short pa cket interrupt enable this bit is set when the shortpacketes bit is written to one . this will enable the short packet interrupt (shortpacket). this bit is cleared when the shortpacketec bit is written to one. this will disable the short packet interrupt (shortpacket). ? stallede: stalled interrupt enable this bit is set when the stalledes bit is written to one. this will enable the stalled interrupt (stalledi). this bit is cleared when the stalledec bit is written to one. this will disable the stalled interrupt (stalledi). ? crcerre: crc error interrupt enable this bit is set when the crcerres bit is written to one. this will enable the crc error interrupt (crcerri). this bit is cleared when the crcerrec bit is written to one. this will disable the crc error interrupt (crcerri). ? overfe: overflow interrupt enable this bit is set when the overfes bit is written to one. this will enable the overflow interrupt (overfi). this bit is cleared when the overfec bit is written to one. this will disable the overflow interrupt (overfi). ? nakine: naked in interrupt enable this bit is set when the nakines bit is written to one. this will enable the naked in interrupt (nakini). this bit is cleared when the nakinec bit is written to one. this will disable the naked in interrupt (nakini). ? hbisoflushe: high bandwidth isochronous in flush interrupt enable this bit is set when the hbisoflushes bit is written to one. this will enable the hbisoflushi interrupt.
720 32072d?04/2011 at32uc3a3/a4 this bit is cleared when the hbisoflush ec bit disable the hb isoflushi interrupt. look at the ufeatures register to know if the high-ban dwidth isochronous feature is supported by the device. ? nakoute: naked out interrupt enable this bit is set when the nakoutes bit is written to one. this will enable the naked out interrupt (nakouti). this bit is cleared when the nakoutec bit is written to one. this will disable the naked out interrupt (nakouti). ? hbisoinerre: high bandwidth isoc hronous in error interrupt enable this bit is set when the hbisoinerres bit is writte n to one. this will enable the hbisoinerri interrupt. this bit is cleared when the hbisoinerrec bit disable the hbisoinerri interrupt. look at the ufeatures register to know if the high-ban dwidth isochronous feature is supported by the device. ? rxstpe: received set up interrupt enable this bit is set when the rxstpes bit is written to on e. this will enable the received setup interrupt (rxstpi). this bit is cleared when the rxstpec bit is written to one. this will disable the received setup interrupt (rxstpi). ? underfe: underflow interrupt enable this bit is set when the underfes bit is written to one. this will enable the underflow interrupt (underfi). this bit is cleared when the underfec bit is written to one. this will disable the underflow interrupt (underfi). ? rxoute: received out data interrupt enable this bit is set when the rxoutes bit is written to one. this will enable the received out data interrupt (rxout). this bit is cleared when the rxoutec bit is written to one. this will disable the received out data interrupt (rxout). ? txine: transmitted in data interrupt enable this bit is set when the txines bit is written to one. th is will enable the transmitted in data interrupt (txini). this bit is cleared when the txinec bit is written to one . this will disable the transmitt ed in data interrupt (txini).
721 32072d?04/2011 at32uc3a3/a4 26.8.2.15 endpoint n control clear register register name: ueconnclr, n in [0..7] access type: write-only offset: 0x0220 + (n * 0x04) read value: 0x00000000 writing a one to a bit in this register will clear the corresponding bit in ueconn. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - stallrqc - nyetdisc epdishdmac 15 14 13 12 11 10 9 8 - fifoconc - nbusybkec - errortransec dataxec mdatec 76543210 short packetec stalledec/ crcerrec overfec nakinec/ hbisoflushec nakoutec/ hbisoinerrec rxstpec/ underfec rxoutec txinec
722 32072d?04/2011 at32uc3a3/a4 26.8.2.16 endpoint n control set register register name: ueconnset, n in [0..7] access type: write-only offset: 0x01f0 + (n * 0x04) read value: 0x00000000 writing a one to a bit in this register will set the corresponding bit in ueconn. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - stallrqs rstdts nyetdiss epdishdmas 15 14 13 12 11 10 9 8 - - killbks nbusybkes - errortranses dataxes mdates 76543210 short packetes stalledes/ crcerres overfes nakines/ hbisoflushes nakoutes/ hbisoinerres rxstpes/ underfes rxoutes txines
723 32072d?04/2011 at32uc3a3/a4 26.8.2.17 device dma channel n next descriptor address register register name: uddmannextdesc , n in [1..7] access type: read/write offset: 0x0310 + (n - 1) * 0x10 reset value: 0x00000000 ? nxtdescaddr: next descriptor address this field contains the bits 31:4 of the 16-byte aligned address of the next channel descriptor to be processed. this field is written either or by descriptor loading. 31 30 29 28 27 26 25 24 nxtdescaddr[31:24] 23 22 21 20 19 18 17 16 nxtdescaddr[23:16] 15 14 13 12 11 10 9 8 nxtdescaddr[15:8] 76543210 nxtdescaddr[7:4] - - - -
724 32072d?04/2011 at32uc3a3/a4 26.8.2.18 device dma channel n hsb address register register name: uddmanaddr , n in [1..7] access type: read/write offset: 0x0314 + (n - 1) * 0x10 reset value: 0x00000000 ? hsbaddr: hsb address this field determines the hsb bus cu rrent address of a channel transfer. the address written to the hsb address bus is hsbaddr rounded down to the nearest word-aligned address, i.e., hsbaddr[1:0] is considered as 0b00 since only word accesses are performed. channel hsb start and end addresses may be aligned on any byte boundary. the user may write this field only when the channel enab led bit (chen) of the uddmanstatus register is cleared. this field is updated at the end of the address phase of the cu rrent access to the hsb bus. it is incremented of the hsb access byte-width. the hsb access width is 4 bytes, or less at packet start or e nd if the start or end address is not aligned on a word boundary. the packet start address is either the channel start address or th e next channel address to be accessed in the channel buffer. the packet end address is either the channel end address or the latest channel address accessed in the channel buffer. the channel start address is written or loaded from the descripto r, whereas the channel end address is either determined by the end of buffer or the end of usb transfer if the bu ffer close input enable bit (buffcloseinen) is set. 31 30 29 28 27 26 25 24 hsbaddr[31:24] 23 22 21 20 19 18 17 16 hsbaddr[23:16] 15 14 13 12 11 10 9 8 hsbaddr[15:8] 76543210 hsbaddr[7:0]
725 32072d?04/2011 at32uc3a3/a4 26.8.2.19 device dma channel n control register register name: uddmancontrol , n in [1..7] access type: read/write offset: 0x0318 + (n - 1) * 0x10 reset value: 0x00000000 ? chbytelength: channel byte length this field determines the total number of bytes to be transferred for this buffer. the maximum channel transfer size 64kb is reached when this field is zero (default value). if the transfer size is unknown, the transfer end is controll ed by the peripheral and this field should be written to zero. this field can be written or descriptor loading only after the uddmanstatus.chen bit has been cleared, otherwise this field is ignored. ? burstlocken: burst lock enable 1: the usb data burst is locked for maximum optimization of hsb busses bandwidth usage and maximization of fly-by duration. 0: the dma never locks the hsb access. ? descldirqen: descriptor loaded interrupt enable 1: the descriptor loaded interrupt is enabled.this interrupt is generated when a descriptor has been loaded from the system bus. 0: the descriptor loaded interrupt is disabled. ? eobuffirqen: end of buffer interrupt enable 1: the end of buffer interrupt is enabled.this interrupt is generated when the channel byte count reaches zero. 0: the end of buffer interrupt is disabled. ? eotirqen: end of usb transfer interrupt enable 1: the end of usb out data transfer interrupt is enabled. th is interrupt is generated only if the buffcloseinen bit is set. 0: the end of usb out data tr ansfer interrupt is disabled. ? dmaenden: end of dma buffer output enable writing a one to this bit will properly complete the usb transfer at the end of the dma transfer. for in endpoint, it means that a short packet (or a zero length packet) will be sent to the usb line to properly closed the usb transfer at the end of the dma transfer. for out endpoint, it means that all the banks will be pro perly released. (nbusybk=0) at the end of the dma transfer. 31 30 29 28 27 26 25 24 chbytelength[15:8] 23 22 21 20 19 18 17 16 chbytelength[7:0] 15 14 13 12 11 10 9 8 -------- 76543210 burstlocken descldirqen eobuffirqen eotirqen dmaenden buffclose inen ldnxtch descen chen
726 32072d?04/2011 at32uc3a3/a4 ? buffcloseinen: buffer close input enable for bulk and interrupt endpoint, writing a one to this bit will automatically close the current dma transfer at the end of the usb out data transfer (received short packet). for full-speed isochronous, it does not make se nse, so buffcloseinen should be left to zero. for high-speed out isochronous, it may make sense. in that case, if buffcloseinen is written to one, the current dma transfer is closed when the received pid packet is not mdata. writing a zero to this bit to disable this feature. ? ldnxtchdescen: load next channel descriptor enable 1: the channel controller loads the next descriptor after the end of the current transfer, i. e. when the uddmanstatus.chen bit is reset. 0: no channel register is loaded after the end of the channel transfer. if the chen bit is written to zero, the next descriptor is i mmediately loaded upon transfer request (endpoint is free for in endpoint, or endpoint is full for out endpoint). table 26-6. dma channel control command summary ? chen: channel enable writing this bit to zero will disabled the dma channel and no transfer will occur upon request. if the ldnxtchdescen bit is written to zero, the channel is frozen and the channel registers may then be read and/or written reliably as soon as both uddmanstatus.chen and chactive bits are zero. writing this bit to one will set the uddmanstatus.chen bit and enable dma channel data transfer. then any pending request will start the transfer. this may be used to start or resume any requested transfer. this bit is cleared when the channel source bus is disabled at end of buffer. if the ldnxtchdescen bit has been cleared by descriptor loading, the user will have to write to one the co rresponding chen bit to start the described transfer, if needed. if a channel request is currently serviced when this bit is zero , the dma fifo buffer is drained until it is empty, then the uddmanstatus.chen bit is cleared. if the ldnxtchdescen bit is set or after this bit clearing, th en the currently loaded descriptor is skipped (no data transfer occurs) and the next descriptor is immediately loaded. ldnxtchdes cen chen current bank 0 0 stop now 0 1 run and stop at end of buffer 1 0 load next descriptor now 1 1 run and link at end of buffer
727 32072d?04/2011 at32uc3a3/a4 26.8.2.20 device dma channel n status register register name: uddmanstatus , n in [1..7] access type: read/write offset: 0x031c + (n - 1) * 0x10 reset value: 0x00000000 ? chbytecnt: channel byte count this field contains the current number of bytes still to be transferred for this buffer. this field is decremented at each dma access. this field is reliable (stable) only if the chen bit is zero. ? descldsta: descriptor loaded status this bit is set when a descriptor has been loaded from the hsb bus. this bit is cleared when read by the user. ? eochbuffsta: end of channel buffer status this bit is set when the channel byte count counts down to zero. this bit is automatically cleared when read by software. ? eotsta: end of usb transfer status this bit is set when the completion of the usb data transfer has closed the dma transfer. it is valid only if uddmancontrol.buffcloseinen is one. this bit is automatically cleared when read by software. ? chactive: channel active 0: the dma channel is no longer trying to source the packet data. 1: the dma channel is currently trying to source packet data, i.e. selected as the highest-priority requesting channel. when a packet transfer cannot be completed due to an eochbuffsta, this bit stays set during the next channel descriptor load (if any) and potentially until usb packet transfer completion, if allowed by the new descriptor. when programming a dma by descriptor (load next descriptor no w), the chactive bit is set only once the dma is running (the endpoint is free for in transaction, the endpoint is full for out transaction). ? chen: channel enabled this bit is set (after one cycle latency) when the l.chen is written to one or when the descriptor is loaded. this bit is cleared when any transfer is ended either due to an elapsed byte count or a usb device initiated transfer end. 0: the dma channel no longer transfers data, and may lo ad the next descriptor if the uddmancontrol.ldnxtchdescen bit is zero. 31 30 29 28 27 26 25 24 chbytecnt[15:8] 23 22 21 20 19 18 17 16 chbytecnt[7:0] 15 14 13 12 11 10 9 8 -------- 76543210 - descld sta eochbuff sta eotsta - - chactive chen
728 32072d?04/2011 at32uc3a3/a4 1: the dma channel is currently enabled and transfers data upon request. if a channel request is currently serviced when the uddmanco ntrol.chen bit is written to zero, the dma fifo buffer is drained until it is empty, then this status bit is cleared.
729 32072d?04/2011 at32uc3a3/a4 26.8.3 usb host registers 26.8.3.1 host general control register register name: uhcon access type: read/write offset: 0x0400 reset value: 0x00000000 ? spdconf: speed configuration this field contains the host speed capability. ? resume: send usb resume writing a one to this bit will generate a usb resume on the usb bus. this bit is cleared when the usb resume has been sent or when a usb reset is requested. writing a zero to this bit has no effect. this bit should be written to one only when the star t of frame generation is enable. (sofe bit is one). ? reset: send usb reset writing a one to this bit will generate a usb reset on the usb bus. this bit is cleared when the usb reset has been sent. it may be useful to write a zero to this bit when a device disc onnection is detected (uhint.ddisci is one) whereas a usb reset is being sent. ? sofe: start of frame generation enable writing a one to this bit will generate sof on the usb bus in full speed mode and keep alive in low speed mode. writing a zero to this bit will disable the sof generation and to leave the usb bus in idle state. this bit is set when a usb reset is requested or an up stream resume interrupt is detected (uhint.rxrsmi). 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - spdconf - resume reset sofe 76543210 -------- spdconf speed 00 normal mode: the host start in full-speed mode and perform a high-speed reset to switch to the high-speed mode if the downstream peripheral is high-speed capable. 0 1 reserved, do not use this configuration 1 0 reserved, do not use this configuration 1 1 full-speed: the host remains to full-speed mo de whatever is the peripheral speed capability.
730 32072d?04/2011 at32uc3a3/a4 26.8.3.2 host global interrupt register register name: uhint access type: read-only offset: 0x0404 reset value: 0x00000000 ? dmanint: dma channel n interrupt this bit is set when an interrupt is triggered by the dma channel n. this triggers a usb interrupt if the corresponding dmaninte is one (uhinte register). this bit is cleared when the uhdmanstatus interrupt source is cleared. ? pnint: pipe n interrupt this bit is set when an interrupt is triggered by the endpoint n (upstan). this triggers a usb interrupt if the corresponding p ipe interrupt enable bit is one (uhinte register). this bit is cleared when the interrupt source is served. ? hwupi: host wake-up interrupt this bit is set when the host controller is in the suspend mode (sofe is zero) and an upstream resume from the peripheral is detected. this bit is set when the host controller is in the suspend mode (sofe is zero) and a peripheral disconnection is detected. this bit is set when the host contro ller is in the idle state (usbsta.vb usrq is zero, no vbus is generated). this interrupt is generated even if the clock is frozen by the frzclk bit. ? hsofi: host start of frame interrupt this bit is set when a sof is issued by the host controller. this triggers a usb interrupt when hsofe is one. when using the host controller in low speed mode, this bit is also set when a keep-alive is sent. this bit is cleared when the hsofic bit is written to one. ? rxrsmi: upstream resu me received interrupt this bit is set when an upstream resume has been received from the device. this bit is cleared when the rxrsmic is written to one. ? rsmedi: downstream resume sent interrupt this bit set when a downstream resume has been sent to the device. this bit is cleared when the rsmedic bit is written to one. ? rsti: usb reset sent interrupt this bit is set when a usb reset has been sent to the device. this bit is cleared when the rstic bit is written to one. 31 30 29 28 27 26 25 24 dma7int dma6int dma5int dma4int dma3int dma2int dma1int - 23 22 21 20 19 18 17 16 ------- 15 14 13 12 11 10 9 8 p7int p6int p5int p4int p3int p2int p1int p0int 76543210 - hwupi hsofi rxrsmi rsmedi rsti ddisci dconni
731 32072d?04/2011 at32uc3a3/a4 ? ddisci: device disconnection interrupt this bit is set when the device has been removed from the usb bus. this bit is cleared when the ddiscic bit is written to one. ? dconni: device conn ection in terrupt this bit is set when a new device has been connected to the usb bus. this bit is cleared when the dconnic bit is written to one.
732 32072d?04/2011 at32uc3a3/a4 26.8.3.3 host global interrupt clear register register name: uhintclr access type: write-only offset: 0x0408 read value: 0x00000000 writing a one to a bit in this register will clear the corresponding bit in uhint. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - hwupic hsofic rxrsmic rsme dic rstic ddiscic dconnic
733 32072d?04/2011 at32uc3a3/a4 26.8.3.4 host global interrupt set register register name: uhintset access type: write-only offset: 0x040c read value: 0x00000000 writing a one to a bit in this register will set the correspondin g bit in uhint, what may be useful for test or debug purposes. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 dma7ints dma6ints dma5ints dma4ints dma3ints dma2ints dma1ints - 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - hwupis hsofis rxrsmis rs medis rstis ddiscis dconnis
734 32072d?04/2011 at32uc3a3/a4 26.8.3.5 host global interrupt enable register register name: uhinte access type: read-only offset: 0x0410 reset value: 0x00000000 ? dmaninte: dma channe l n interrupt enable this bit is set when the dmanintes bit is written to on e. this will enable the dma channel n interrupt (dmanint). this bit is cleared when the dmanintec bit is written to one. this will disable the dma channel n interrupt (dmanint). ? pninte: pipe n interrupt enable this bit is set when the pnintes bit is written to one. this will enable the pipe n interrupt (pnint). this bit is cleared when the pnintec bit is written to one. this will disable the pipe n interrupt (pnint). ? hwupie: host wake-up interrupt enable this bit is set when the hwupies bit is written to on e. this will enable the host wake-up interrupt (hwupi). this bit is cleared when the hwupiec bit is written to one. this will disabl e the host wake-up interrupt (hwupi). ? hsofie: host start of frame interrupt enable this bit is set when the hsofies bit is written to one. this will enable the host start of frame interrupt (hsofi). this bit is cleared when the hsofiec bit is written to one. this will disable the host start of frame interrupt (hsofi). ? rxrsmie: upstream resume received interrupt enable this bit is set when the rxrsmies bit is written to one. this will enable the upstream resume received interrupt (rxrsmi). this bit is cleared when the rxrsmiec bit is written to on e. this will disable the downstream resume interrupt (rxrsmi). ? rsmedie: downstream resu me sent interrupt enable this bit is set when the rsmedies bit is written to one. this will enable the downstream resume interrupt (rsmedi). this bit is cleared when the rsmediec bit is written to on e. this will disable the downstream resume interrupt (rsmedi). ? rstie: usb reset sent interrupt enable this bit is set when the rsties bit is written to one. this will enable the usb reset sent interrupt (rsti). this bit is cleared when the rstiec bit is written to one. this will disable the usb reset sent interrupt (rsti). ? ddiscie: device discon nection interrupt enable this bit is set when the ddiscies bit is written to one. this will enable the device disconnection interrupt (ddisci). this bit is cleared when the ddisciec bit is written to one. this will disable the device disconnection interrupt (ddisci). ? dconnie: device connection interrupt enable this bit is set when the dconnies bit is written to one. th is will enable the device connection interrupt (dconni). this bit is cleared when the dconniec bit is written to on e. this will disable the device connection interrupt (dconni). 31 30 29 28 27 26 25 24 dma7inte dma6inte dma5inte dma4inte dma3inte dma2inte dma1inte - 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 p7inte p6inte p5inte p4inte p3inte p2inte p1inte p0inte 76543210 - hwupie hsofie rxrsmie rs medie rstie ddiscie dconnie
735 32072d?04/2011 at32uc3a3/a4 26.8.3.6 host global interrupt enable clear register register name: uhinteclr access type: write-only offset: 0x0414 read value: 0x00000000 writing a one to a bit in this register will clear the corresponding bit in uhinte. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 dma7intec dma6intec dma5intec dma4i ntec dma3intec dma2intec dma1intec - 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 p7intec p6intec p5inte c p4intec p3intec p2intec p1intec p0intec 76543210 - hwupiec hsofiec rxrsmiec rsmediec rstiec ddisciec dconniec
736 32072d?04/2011 at32uc3a3/a4 26.8.3.7 host global interrupt enable set register register name: uhinteset access type: write-only offset: 0x0418 read value: 0x00000000 writing a one to a bit in this register will set the corresponding bit in uhint. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 dma7intes dma6intes dma5intes dma4i ntes dma3intes dma2intes dma1intes - 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 p7intes p6intes p5intes p4intes p3intes p2intes p1intes p0intes 76543210 - hwupies hsofies rxrsmies rsmedies rsties ddiscies dconnies
737 32072d?04/2011 at32uc3a3/a4 26.8.3.8 host frame number register register name: uhfnum access type: read/write offset: 0x0420 reset value: 0x00000000 ? flenhigh: frame length in full speed mode, this field contains the 8 high-order bits of the 16-bit internal frame counter (at 30mhz, counter length is 30000 to ensure a sof generation every 1 ms). in high speed mode, this field contains the 8 high-order bits of the 16-bit internal frame counter (at 30mhz, counter length is 3750 to ensure a sof generation every 125 us). ? fnum: frame number this field contains the current sof number. this field can be written. in this case, the mfnum field is reset to zero. ? mfnum: micro frame number this field contains the current micro frame num ber (can vary from 0 to 7) updated every 125us. when operating in full-speed mode, this field is tied to zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 flenhigh 15 14 13 12 11 10 9 8 - - fnum[10:5] 76543210 fnum[4:0] mfnum
738 32072d?04/2011 at32uc3a3/a4 26.8.3.9 host address 1 register register name: uhaddr1 access type: read/write offset: 0x0424 reset value: 0x00000000 ? uhaddrp3: usb host address this field contains the address of the pipe3 of the usb device. this field is cleared when a usb reset is requested. ? uhaddrp2: usb host address this field contains the address of the pipe2 of the usb device. this field is cleared when a usb reset is requested. ? uhaddrp1: usb host address this field contains the address of the pipe1 of the usb device. this field is cleared when a usb reset is requested. ? uhaddrp0: usb host address this field contains the address of the pipe0 of the usb device. this field is cleared when a usb reset is requested. 31 30 29 28 27 26 25 24 - uhaddrp3 23 22 21 20 19 18 17 16 - uhaddrp2 15 14 13 12 11 10 9 8 - uhaddrp1 76543210 - uhaddrp0
739 32072d?04/2011 at32uc3a3/a4 26.8.3.10 host address 2 register register name: uhaddr2 access type: read/write offset: 0x0428 reset value: 0x00000000 ? uhaddrp7: usb host address this field contains the address of the pipe7 of the usb device. this field is cleared when a usb reset is requested. ? uhaddrp6: usb host address this field contains the address of the pipe6 of the usb device. this field is cleared when a usb reset is requested. ? uhaddrp5: usb host address this field contains the address of the pipe5 of the usb device. this field is cleared when a usb reset is requested. ? uhaddrp4: usb host address this field contains the address of the pipe4 of the usb device. this field is cleared when a usb reset is requested. 31 30 29 28 27 26 25 24 - uhaddrp7 23 22 21 20 19 18 17 16 - uhaddrp6 15 14 13 12 11 10 9 8 - uhaddrp5 76543210 - uhaddrp4
740 32072d?04/2011 at32uc3a3/a4 26.8.3.11 pipe enable/reset register register name: uprst access type: read/write offset: 0x0041c reset value: 0x00000000 ? prstn: pipe n reset writing a one to this bit will reset the pipe n fifo. this resets the endpoint n registers (upcfgn, upstan, up conn) but not the endpoint configuration (alloc, pbk, psize, ptoken, ptype, pepnum, intfrq). all the endpoint mechanism (fifo counter, reception, transmission, etc.) is rese t apart from the data toggle management. the endpoint configuration remains active and the endpoint is still enabled. writing a zero to this bit will complete the reset operation and allow to start using the fifo. ? penn: pipe n enable writing a one to this bit will enable the pipe n. writing a zero to this bit will disable the pipe n, what forces the pipe n state to inactive and resets the pipe n registers (u pcfgn, upstan, upconn) but not the pipe c onfiguration (alloc, pbk, psize). 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 prst7 prst6 prst5 prst4 prst3 prst2 prst1 prst0 15 14 13 12 11 10 9 8 -------- 76543210 pen7 pen6 pen5 pen4 pen3 pen2 pen1 pen0
741 32072d?04/2011 at32uc3a3/a4 26.8.3.12 pipe n configuration register register name: upcfgn, n in [0..7] access type: read/write offset: 0x0500 + (n * 0x04) reset value: 0x00000000 ? intfrq: pipe interrupt request frequency this field contains the maximum value in millisecond of the polling period for an interrupt pipe. this value has no effect for a non-interrupt pipe. this field is cleared upon sending a usb reset. ? binterval: binterval parameter for the bulk-out/ping transaction this field contains the ping/bulk-out period. if binterval>0 and pingen=1, one ping token is sent every binterval micro-frame until it is acked by the peripheral. if binterval=0 and ping en=1, multiple consecutive ping token is sent in the same micro-frame until it is acked. if binterval>0 and pingen=0, one out token is sent every binterval micro-frame until it is acked by the peripheral. if binterval=0 and pingen=0, multiple consecutive out to ken is sent in the same mi cro-frame until it is acked. this value must be in the range from 0 to 255. ? pingen: ping enable this bit is relevant for high-speed bulk-out transaction only (including the control data stage an d the control status stage). writing a zero to this bit will disable the ping protocol. writing a one to this bit will enable the ping mechanism according to the usb 2.0 standard. this bit is cleared upon sending a usb reset. ? pepnum: pipe endpoint number this field contains the number of the endpoint tar geted by the pipe. this value is from 0 to 15. this field is cleared upon sending a usb reset. ? ptype: pipe type this field contains the pipe type. 31 30 29 28 27 26 25 24 intfrq/binterval 23 22 21 20 19 18 17 16 - - - pingen pepnum 15 14 13 12 11 10 9 8 - - ptype - autosw ptoken 76543210 - psize pbk alloc - ptype pipe type 0 0 control
742 32072d?04/2011 at32uc3a3/a4 this field is cleared upon sending a usb reset. ? autosw: automatic switch this bit is cleared upon sending a usb reset. 1: the automatic bank switching is enabled. 0: the automatic bank switching is disabled. ? ptoken: pipe token this field contains the endpoint token. ? psize: pipe size this field contains the size of each pipe bank. this field is cleared upon sending a usb reset. ? pbk: pipe banks this field contains the number of banks for the pipe. for control endpoints, a single-bank pipe (0b00) should be selected. this field is cleared upon sending a usb reset. 0 1 isochronous 10bulk 1 1 interrupt ptoken endpoint direction 00 setup 01 in 10 out 11 reserved psize endpoint size 0 0 0 8 bytes 00116 bytes 01032 bytes 01164 bytes 1 0 0 128 bytes 1 0 1 256 bytes 1 1 0 512 bytes 1 1 1 1024 bytes pbk endpoint banks 0 0 1 (single-bank pipe) 0 1 2 (double-bank pipe) 1 0 3 (triple-bank pipe) if supported (see table 26-1 on page 636 ). 11reserved ptype pipe type
743 32072d?04/2011 at32uc3a3/a4 ? alloc: pipe memory allocate writing a one to this bit will allocate the pipe memory. writing a zero to this bit will free the pipe memory. this bit is cleared when a usb reset is requested. refer to the dpram management chapter for more details.
744 32072d?04/2011 at32uc3a3/a4 26.8.3.13 pipe n status register register name: upstan, n in [0..7] access type: read-only offset: 0x0530 + (n * 0x04) reset value: 0x00000000 ? pbyct: pipe byte count this field contains the byte count of the fifo. for out pipe, incremented after each byte written by the user into the pipe and decremented after each byte sent to the peripheral. for in pipe, incremented after each byte received from the periphe ral and decremented after each byte read by the user from the pipe. this field may be updated 1 clock cycle after the rwall bit changes , so the user should not poll this field as an interrupt bit . ? cfgok: configuration ok status this bit is set/cleared when the upcfgn.alloc bit is set. this bit is set if the pipe n number of banks (upcfgn.pbk) and size (upcfgn.psize) are correct compared to the maximal allowed number of banks and size for this pipe an d to the maximal fifo size (i.e., the dpram size). if this bit is cleared, the user sh ould rewrite correct values ot the pbk and psize field in the upcfgn register. ? rwall: read/write allowed for out pipe, this bit is set when the current bank is not full, i.e., the software can write further data into the fifo. for in pipe, this bit is set when the current bank is not empt y, i.e., the software can read further data from the fifo. this bit is cleared otherwise. this bit is also cleared when the rxstall or the perr bit is one. ? currbk: current bank for non-control pipe, this field indicates the number of the current bank. 31 30 29 28 27 26 25 24 - pbyct[10:4] 23 22 21 20 19 18 17 16 pbyct[3:0] - cfgok - rwall 15 14 13 12 11 10 9 8 currbk nbusybk - - dtseq 76543210 short packeti rxstalldi/ crcerri overfi nakedi perri txstpi/ underfi txouti rxini currbk current bank 00bank0
745 32072d?04/2011 at32uc3a3/a4 this field may be updated 1 clock cycle after the rwall bit chang es, so the user shall not poll this field as an interrupt bit. ? nbusybk: number of busy banks this field indicates the number of busy bank. for out pipe, this field indicates the number of busy bank(s), filled by the user, ready for out transfer. when all banks are busy, this triggers an pnint in terrupt if upconn.nbusybke is one. for in pipe, this field indicates the number of busy bank(s) filled by in transaction from the device. when all banks are free, this triggers an pnint interrup t if upconn.nbusybke is one. ? dtseq: data toggle sequence this field indicates the data pid of the current bank. for out pipe, this field indicates the data toggle of the next packet that will be sent. for in pipe, this field indicates the data toggle of the received packet stored in the current bank. ? shortpacketi: short packet interrupt this bit is set when a short packet is received by the host controller (packet length inferior to the psize programmed field). this bit is cleared when the shortpacketic bit is written to one. ? rxstalldi: received stalled interrupt this bit is set, for all endpoints but isochronous, when a stal l handshake has been received on the current bank of the pipe. the pipe is automatically frozen. this trigger s an interrupt if the rxstalle bit is one. this bit is cleared when the rxstalldic bit is written to one. ? crcerri: crc error interrupt this bit is set, for isochronous endpoint, when a crc error occurs on the current bank of the pipe. this triggers an interrupt if the txstpe bit is one. this bit is cleared when the crcerric bit is written to one. ? overfi: overflow interrupt this bit is set when the current pipe has received more data than the maximum length of the current pipe. an interrupt is triggered if the overfie bit is one. this bit is cleared when the overfic bit is written to one. ? nakedi: naked interrupt this bit is set when a nak has been received on the current bank of the pipe. this trig gers an interrupt if the nakede bit is o ne. 01bank1 1 0 bank2 if supported (see table 26-1 on page 636 ). 11reserved nbusybk number of busy bank 0 0 all banks are free. 0 1 1 busy bank 1 0 2 busy banks if supported (see table 26-1 on page 636 ). 11reserved dtseq data toggle sequence 00data0 01data1 10reserved 11reserved currbk current bank
746 32072d?04/2011 at32uc3a3/a4 this bit is cleared when the nakedic bit written to one. ? perri: pipe error interrupt this bit is set when an error occurs on the current bank of t he pipe. this triggers an interrupt if the perre bit is set. refer s to the uperrn register to determine the source of the error. this bit is cleared when the error source bit is cleared. ? txstpi: transmitted setup interrupt this bit is set, for control endpoints, when the current setup bank is free and can be filled. this triggers an interrupt if th e txstpe bit is one. this bit is cleared when the txstpic bit is written to one. ? underfi: underflow interrupt this bit is set, for isochronous and interrupt in/out pipe, when an error flow occurs. this triggers an interrupt if the underf ie bit is one. this bit is set, for isochronous or interrupt out pipe, when a tr ansaction underflow occurs in the current pipe. (the pipe can? t send the out data packet in time because the current bank is not ready). a zero-length-packe t (zlp) will be sent instead of. this bit is set, for isochronous or interrupt in pipe, when a transaction flow error occurs in the current pipe. i.e, the curre nt bank of the pipe is not free whereas a new in usb packet is received . this packet is not stored in the bank. for interrupt pipe, the overflowed packet is acked to respect the usb standard. this bit is cleared when the underfiec bit is written to one. ? txouti: transmitted out data interrupt this bit is set when the current out bank is free and can be filled. this triggers an interrupt if the txoute bit is one. this bit is cleared when the txoutic bit is written to one. ? rxini: received in data interrupt this bit is set when a new usb message is stored in the current bank of the pipe. this triggers an interrupt if the rxine bit i s one. this bit is cleared when the rxinic bit is written to one.
747 32072d?04/2011 at32uc3a3/a4 26.8.3.14 pipe n status clear register register name: upstanclr, n in [0..7] access type: write-only offset: 0x0560 + (n * 0x04) read value: 0x00000000 writing a one to a bit in this register will clear the corresponding bit in upstan. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 short packetic rxstalldi c/ crcerric overfic nakedic - txstpic/ underfic txoutic rxinic
748 32072d?04/2011 at32uc3a3/a4 26.8.3.15 pipe n status set register register name: upstanset, n in [0..7] access type: write-only offset: 0x0590 + (n * 0x04) read value: 0x00000000 writing a one to a bit in this register will set the corresponding bit in upstan, what may be useful for test or debug purposes . writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 - - - nbusybks - - - - 76543210 short packetis rxstalldis / crcerris overfis nakedis perris txstpis/ underfis txoutis rxinis
749 32072d?04/2011 at32uc3a3/a4 26.8.3.16 pipe n control register register name: upconn, n in [0..7] access type: read-only offset: 0x05c0 + (n * 0x04) reset value: 0x00000000 ? rstdt: reset data toggle this bit is set when the rstdts bit is written to one. this will reset the data toggle to its initial value for the current pip e. this bit is cleared when proceed. ? pfreeze: pipe freeze this bit is set when the pfreezes bit is written to one or when the pipe is not configured or when a stall handshake has been received on this pipe or when an error occurs on the pipe (perr is one) or when (inrq+1) in requests have been processed or when after a pipe reset (uprst.prstn rising) or a pipe enable (uprst.pen rising). this will freeze the pipe requests generation. this bit is cleared when the pfreezec bit is writt en to one. this will enable the pipe request generation. ? pdishdma: pipe interrupts disable hdma request enable see the ueconn.epdishdma bit description. ? fifocon: fifo control for out and setup pipe: this bit is set when the current bank is free , at the same time than txouti or txstpi. this bit is cleared when the fifoconc bit is written to one. this will send the fifo data and switch the bank. for in pipe: this bit is set when a new in message is stored in the current bank, at the same time than rxini. this bit is cleared when the fifoconc bit is written to one. this will free the current bank and switch to the next bank. ? nbusybke: number of bu sy banks interrupt enable this bit is set when the nbusybkes bit is written to one.this will enable the transmitted in data interrupt (nbusybke). this bit is cleared when the nbusybkec bit is written to one. this will disable the transmitted in data interrupt (nbusybke). ? shortpacketie: short packet interrupt enable this bit is set when the shortpacketes bit is written to one. this will enable the transmitted in data it (shortpacketie). this bit is cleared when the shortpacketec bit is written to one. this will disable the transmitted in data it (shortpackete). 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - - rstdt pfreeze pdishdma 15 14 13 12 11 10 9 8 - fifocon - nbusybke - - - - 76543210 short packetie rxstallde/ crcerre overfie nakede perre txstpe/ underfie txoute rxine
750 32072d?04/2011 at32uc3a3/a4 ? rxstallde: received st alled interrupt enable this bit is set when the rxstalldes bit is written to one. this will enable the transmitted in data interrupt (rxstallde). this bit is cleared when the rxstalldec bit is written to one. this will disable the transmitted in data interrupt (rxstallde). ? crcerre: crc error interrupt enable this bit is set when the crcerres bit is written to one. this will enable the transmitted in data interrupt (crcerre). this bit is cleared when the crcerrec bit is written to one. this will disable the transmitted in data interrupt (crcerre). ? overfie: overflow interrupt enable this bit is set when the overfies bit is written to one. this will enable the transmitted in data interrupt (overfie). this bit is cleared when the overfiec bit is written to one . this will disable the transmitted in data interrupt (overfie). ? nakede: naked interrupt enable this bit is set when the nakedes bit is written to one. this will enable the transmitted in data interrupt (nakede). this bit is cleared when the nakedec bit is written to one. this will disable the transmitted in data interrupt (nakede). ? perre: pipe error interrupt enable this bit is set when the perres bit is written to one. this will enable the transmitted in data interrupt (perre). this bit is cleared when the perrec bit is written to one. this will disable the transmitted in data interrupt (perre). ? txstpe: transmitted set up interrupt enable this bit is set when the txstpes bit is written to one. this will enable the transmitted in data interrupt (txstpe). this bit is cleared when the txstpec bit is written to one. this will disable the transmitted in data interrupt (txstpe). ? underfie: underflo w interrupt enable this bit is set when the underfies bit is written to one. this will enable the transmitted in data interrupt (underfie). this bit is cleared when the underfiec bit is written to one. this will disable the transmitted in data interrupt (underfie). ? txoute: transmitted out data interrupt enable this bit is set when the txoutes bit is written to one. this will enable the transmitted in data interrupt (txoute). this bit is cleared when the txoutec bit is written to one. this will disable the transmitted in data interrupt (txoute). ? rxine: received in data interrupt enable this bit is set when the rxines bit is written to one. this will enable the transmitted in data interrupt (rxine). this bit is cleared when the rxinec bit is written to one. this will disable the transmitted in data interrupt (rxine).
751 32072d?04/2011 at32uc3a3/a4 26.8.3.17 pipe n control clear register register name: upconnclr, n in [0..7] access type: write-only offset: 0x0620 + (n * 0x04) read value: 0x00000000 writing a one to a bit in this register will clear the corresponding bit in upconn. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - - - pfreezec pdishdmac 15 14 13 12 11 10 9 8 - fifoconc - nbusybkec ---- 76543210 short packetiec rxstalldec / crcerrec overfiec nakedec perrec txstpec/ underfiec txoutec rxinec
752 32072d?04/2011 at32uc3a3/a4 26.8.3.18 pipe n control set register register name: upconnset, n in [0..7] access type: write-only offset: 0x05f0 + (n * 0x04) read value: 0x00000000 writing a one to a bit in this register will set the corresponding bit in upconn. writing a zero to a bit in this register has no effect. this bit always reads as zero. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - - rstdts pfreezes pdishdmas 15 14 13 12 11 10 9 8 --- nbusybkes ---- 76543210 short packeties rxstalldes / crcerres overfies nakedes perres txstpes/ underfies txoutes rxines
753 32072d?04/2011 at32uc3a3/a4 26.8.3.19 pipe n in request register register name: upinrqn, n in [0..7] access type: read/write offset: 0x0650 + (n * 0x04) reset value: 0x00000000 ? inmode: in request mode writing a one to this bit will allow the usbb to perform infinite in requests when the pipe is not frozen. writing a zero to this bit will perform a pre-defined nu mber of in requests. this number is the inrq field. ? inrq: in request number before freeze this field contains the number of in transactions before the usbb freezes the pipe. the usbb will perform (inrq+1) in requests before to freeze the pipe. this counter is automatica lly decreased by 1 each time a in request has been successfully performed. this register has no effect when the in mode bit is one (infinite in requests generation till the pipe is not frozen). 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------inmode 76543210 inrq
754 32072d?04/2011 at32uc3a3/a4 26.8.3.20 pipe n error register register name: uperrn, n in [0..7] access type: read/write offset: 0x0680 + (n * 0x04) reset value: 0x00000000 ? counter: error counter this field is incremented each time an error occu rs (crc16, timeout, pid, datapid or datatgl). this field is cleared when receiving a good usb packet without any error. when this field reaches 3 (i.e., 3 consecutive errors), th is pipe is automatically fr ozen (upconn.pfreeze is set). writing 0b00 to this field will clear the counter. ? crc16: crc16 error this bit is set when a crc16 error has been detected. writing a zero to this bit will clear the bit. writing a one to this bit has no effect. ? timeout: time-out error this bit is set when a time-out error has been detected. writing a zero to this bit will clear the bit. writing a one to this bit has no effect. ?pid: pid error this bit is set when a pid error has been detected. writing a zero to this bit will clear the bit. writing a one to this bit has no effect. ? datapid: data pid error this bit is set when a data pid error has been detected. writing a zero to this bit will clear the bit. writing a one to this bit has no effect. ? datatgl: data toggle error this bit is set when a data toggle error has been detected. writing a zero to this bit will clear the bit. writing a one to this bit has no effect. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - counter crc16 timeout pid datapid datatgl
755 32072d?04/2011 at32uc3a3/a4 26.8.3.21 host dma channel n next descriptor address register register name: uhdmannextdesc , n in [1..7] access type: read/write offset: 0x0710 + (n - 1) * 0x10 reset value: 0x00000000 same as section 26.8.2.17 . 31 30 29 28 27 26 25 24 nxtdescaddr[31:24] 23 22 21 20 19 18 17 16 nxtdescaddr[23:16] 15 14 13 12 11 10 9 8 nxtdescaddr[15:8] 76543210 nxtdescaddr[7:4] - - - -
756 32072d?04/2011 at32uc3a3/a4 26.8.3.22 host dma channel n hsb address register register name: uhdmanaddr , n in [1..7] access type: read/write offset: 0x0714 + (n - 1) * 0x10 reset value: 0x00000000 same as section 26.8.2.18 . 31 30 29 28 27 26 25 24 hsbaddr[31:24] 23 22 21 20 19 18 17 16 hsbaddr[23:16] 15 14 13 12 11 10 9 8 hsbaddr[15:8] 76543210 hsbaddr[7:0]
757 32072d?04/2011 at32uc3a3/a4 26.8.3.23 usb host dma channel n control register register name: uhdmancontrol , n in [1..7] access type: read/write offset: 0x0718 + (n - 1) * 0x10 reset value: 0x00000000 same as section 26.8.2.19 . (just replace the in endpoint term by out endpoint, and vice-versa) 31 30 29 28 27 26 25 24 chbytelength[15:8] 23 22 21 20 19 18 17 16 chbytelength[7:0] 15 14 13 12 11 10 9 8 -------- 76543210 burstloc ken descld irqen eobuff irqen eotirqen dmaenden buffclose inen ldnxtchd escen chen
758 32072d?04/2011 at32uc3a3/a4 26.8.3.24 usb host dma channel n status register register name: uhdmanstatus , n in [1..7] access type: read/write offset: 0x071c + (n - 1) * 0x10 reset value: 0x00000000 same as section 26.8.2.20 . 31 30 29 28 27 26 25 24 chbytecnt[15:8] 23 22 21 20 19 18 17 16 chbytecnt[7:0] 15 14 13 12 11 10 9 8 -------- 76543210 - descld sta eochbuffs ta eotsta - - chactive chen
759 32072d?04/2011 at32uc3a3/a4 26.8.4 usb pipe/endpoint n fifo data register (usbfifondata) the application has access to the physical dp ram reserved for the endpoint/pipe through a 64kb virtual address space. the application ca n access anywhere in t he virtual 64kb segment (linearly or fixedly) as the dpram fifo address increment is fully handled by hardware. byte, half-word and word access are supported. data should be access in a big-endian way. for instance, if the app lication wants to write into the endp oint/pipe3, it can access anywhere in the usbfifo3data hsb segment address. i.e : an access to the 0x30000 offset, is strictly equivalent to an access to the 0x3fffc offset. note that the virtual address space size (64kb) has nothing to do with the endpoint/pipe size. disabling the usbb (by writing a zero to the usbe bit) does not reset the dpram.
760 32072d?04/2011 at32uc3a3/a4 26.9 module configuration the specific configuration for t he usbb instance is listed in the following tables. the module bus clocks listed here are connecte d to the system bus clocks. pleas e refer to the power manager chapter for details. table 26-7. module clock name module name clock name clock name usbb clk_usbb_hsb clk_usbb_pb table 26-8. register reset values register reset value uvers 0x00000320 ufeatures 0x00014478 uaddrsize 0x00001000 uname1 0x48555342 uname2 0x004f5447
761 32072d?04/2011 at32uc3a3/a4 27. timer/counter (tc) rev: 2.2.3.3 27.1 features ? three 16-bit timer counter channels ? a wide range of functions including: ? frequency measurement ? event counting ? interval measurement ? pulse generation ?delay timing ? pulse width modulation ? up/down capabilities ? each channel is user-conf igurable and contains: ? three external clock inputs ? five internal clock inputs ? two multi-purpose input/output signals ? internal interrupt signal ? two global registers that act on all three tc channels 27.2 overview the timer counter (tc) includes three identical 16-bit timer counter channels. each channel can be independently programmed to perform a wide range of functions including frequency measurement, event counting, interval measurement, pulse generation, delay timing, and pulse width modulation. each channel has three external clock inputs, fi ve internal clock inputs, and two multi-purpose input/output signals which can be configured by the user. each channel drives an internal inter- rupt signal which can be programmed to generate processor interrupts. the tc block has two global registers which act upon all three tc channels. the block control register (bcr) allows the th ree channels to be started simultaneously with the same instruction. the block mode register (bmr) defines the ex ternal clock inputs for each channel, allowing them to be chained.
762 32072d?04/2011 at32uc3a3/a4 27.3 block diagram figure 27-1. tc block diagram 27.4 i/o lines description 27.5 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 27.5.1 i/o lines the pins used for interfacing the compliant external devices may be multiplexed with i/o lines. the user must first program the i/o controller to assign the tc pins to their peripheral functions. i/o co n t r o l l e r tc2xc2s int0 int1 int2 tioa0 tioa1 tioa2 tiob0 tiob1 tiob2 xc2 tclk0 tclk1 tclk2 tclk0 tclk1 tclk2 tclk0 tclk1 tclk2 tioa1 tioa2 tioa0 tioa2 tioa1 interrupt controller clk0 clk1 clk2 a0 b0 a1 b1 a2 b2 timer count er tiob tioa tiob sync timer_clock1 tioa sync sync tioa tiob timer_clock2 timer_clock3 timer_clock4 timer_clock5 xc1 xc0 xc0 xc2 xc1 xc0 xc1 xc2 timer/counter channel 2 timer/counter channel 1 timer/counter channel 0 tc1xc1s tc0xc0s tioa0 table 27-1. i/o lines description pin name description type clk0-clk2 external clock input input a0-a2 i/o line a input/output b0-b2 i/o line b input/output
763 32072d?04/2011 at32uc3a3/a4 27.5.2 power management if the cpu enters a sleep mode that disables cl ocks used by the tc, the tc will stop functioning and resume operation after the system wakes up from sleep mode. 27.5.3 clocks the clock for the tc bus interface (clk_tc) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to disable the tc before disabling the clock, to avoid freezing the tc in an undefined state. 27.5.4 interrupts the tc interrupt request line is connected to the interrupt controller. using the tc interrupt requires the interrupt controller to be programmed first. 27.5.5 debug operation the timer counter clocks are frozen du ring debug operation, unless the ocd system keeps peripherals running in debug operation. 27.6 functional description 27.6.1 tc description the three channels of the timer counter are independent and identical in operation. the regis- ters for channel programming are listed in figure 27-3 on page 778 . 27.6.1.1 channel i/o signals as described in figure 27-1 on page 762 , each channel has the following i/o signals. 27.6.1.2 16-bit counter each channel is organized around a 16-bit counter. the value of the counter is incremented at each positive edge of the selected clock. when the counter has reached the value 0xffff and passes to 0x0000, an overflow occurs and the counter overflow status bit in the channel n sta- tus register (srn.covfs) is set. the current value of the counter is accessible in real time by reading the channel n counter value register (cvn). the counter can be reset by a trigger. in this case, the counter value passes to 0x0000 on the next valid edge of the selected clock. table 27-2. channel i/o signals description block/channel sign al name description channel signal xc0, xc1, xc2 external clock inputs tioa capture mode: timer counter input waveform mode: timer counter output tiob capture mode: timer counter input waveform mode: timer counter input/output int interrupt signal output sync synchronization input signal
764 32072d?04/2011 at32uc3a3/a4 27.6.1.3 clock selection at block level, input clock signals of each channel can either be connected to the external inputs tclk0, tclk1 or tclk2, or be connected to the configurable i/o signals a0, a1 or a2 for chaining by writing to the bmr register. see figure 27-2 on page 764 . each channel can independently select an internal or external clock source for its counter: ? internal clock signals: timer_cl ock1, timer_clock2, timer_clock3, timer_clock4, timer_clock5. see the module configuration chapter for details about the connection of these clock sources. ? external clock signals: xc0, xc1 or xc2. see the module configuration chapter for details about the connection of these clock sources. this selection is made by the clock sele ction field in the channel n mode register (cmrn.tcclks). the selected clock can be inverted with the clock invert bit in cmrn (cmrn.clki). this allows counting on the opposite edges of the clock. the burst function allows the clock to be valida ted when an external signal is high. the burst signal selection field in the cmrn regi ster (cmrn.burst) defines this signal. note: in all cases, if an external clock is used, the du ration of each of its leve ls must be longer than the clk_tc period. the external clock frequency must be at least 2.5 times lower than the clk_tc. figure 27-2. clock selection 27.6.1.4 clock control the clock of each counter can be controlled in two different ways: it can be enabled/disabled and started/stopped. see figure 27-3 on page 765 . timer_clock5 xc2 tcclks clki burst 1 selected clock xc1 xc0 timer_clock4 timer_clock3 timer_clock2 timer_clock1
765 32072d?04/2011 at32uc3a3/a4 ? the clock can be enabled or disabled by the user by writing to the counter clock enable/disable command bits in the channel n clock contro l register (ccrn.clken and ccrn.clkdis). in capture mode it can be disabled by an rb load event if the counter clock disable with rb loading bit in cmrn is written to one (cmrn.ldbdis). in waveform mode, it can be disabled by an rc compare event if the counter clock disable with rc compare bit in cmrn is written to one (cmrn.cpcdis). when disabled, the start or the stop actions have no effect: only a clken command in ccrn can re-enable the clock. when the clock is enabled, the clock enabling status bit is set in srn (srn.clksta). ? the clock can also be started or stopped: a trigger (software, synchro, external or compare) always starts the clock. in capture mode the clock can be stopped by an rb load event if the counter clock stopped with rb loading bit in cmrn is written to one (cmrn.ldbstop). in waveform mode it can be stopped by an rc compare event if the counter clock stopped with rc compare bit in cmrn is written to one (cmrn.cpcstop). the start and the stop commands have effect only if the clock is enabled. figure 27-3. clock control 27.6.1.5 tc operating modes each channel can independently operate in two different modes: ? capture mode provides measurement on signals. ? waveform mode provides wave generation. the tc operating mode selection is done by writing to the wave bit in the ccrn register (ccrn.wave). in capture mode, tioa and tiob are configured as inputs. in waveform mode, tioa is always configured to be an output and tiob is an output if it is not selected to be the external trigger. qs r s r q clksta clken clkdis stop event disable counter clock selected clock trigger event
766 32072d?04/2011 at32uc3a3/a4 27.6.1.6 trigger a trigger resets the counter and starts the counter clock. three types of triggers are common to both modes, and a fourth external trigger is available to each mode. the following triggers are common to both modes: ? software trigger: each channel has a software trigger, available by writing a one to the software trigger command bi t in ccrn (ccrn.swtrg). ? sync: each channel has a synchronization signal sync. when asserted, this signal has the same effect as a software trigger. the sync signals of all channels are asserted simultaneously by writing a one to the synchro command bit in the bcr register (bcr.sync). ? compare rc trigger: rc is implemented in each channel and can provide a trigger when the counter value matches the rc value if the rc compare trigger enable bit in cmrn (cmrn.cpctrg) is written to one. the channel can also be configured to have an external trigger. in capture mode, the external trigger signal can be selected between tioa and tiob. in waveform mode, an external event can be programmed to be one of the following si gnals: tiob, xc0, xc1, or xc2. this external event can then be programmed to perform a trigger by writing a one to the external event trig- ger enable bit in cmrn (cmrn.enetrg). if an external trigger is used, the duration of the pulses must be longer than the clk_tc period in order to be detected. regardless of the trigger used, it will be taken into account at the following active edge of the selected clock. this means that the counter value can be read differently from zero just after a trigger, especially when a low frequency signal is selected as the clock. 27.6.2 capture operating mode this mode is entered by writin g a zero to the cmrn.wave bit. capture mode allows the tc channel to perform measurements such as pulse timing, fre- quency, period, duty cycle and phase on tioa and tiob sig nals which are considered as inputs. figure 27-4 on page 768 shows the configuration of the tc channel when programmed in cap- ture mode. 27.6.2.1 capture registers a and b registers a and b (ra and rb) are used as capture registers. this means that they can be loaded with the counter value when a progr ammable event occurs on the signal tioa. the ra loading selection field in cmrn (cmrn.ldra) defines the tioa edge for the loading of the ra register, and the rb loading selection fi eld in cmrn (cmrn.ldrb) defines the tioa edge for the loading of the rb register. ra is loaded only if it has not been loaded since the last trigger or if rb has been loaded since the last loading of ra. rb is loaded only if ra has been loaded sinc e the last trigger or t he last loading of rb. loading ra or rb before the read of the last value loaded sets the load overrun status bit in srn (srn.lovrs). in this case, the old value is overwritten.
767 32072d?04/2011 at32uc3a3/a4 27.6.2.2 trigger conditions in addition to the sync signal, the software trigger and the rc compare trigger, an external trig- ger can be defined. the tioa or tiob external trigger selection bit in cmrn (cmrn.abetrg) selects tioa or tiob input signal as an external trigger. the external trigger edge selection bit in cmrn (cmrn.etredg) defines the edge (rising, falling or both) detected to generate an external trig- ger. if cmrn.etrgedg is zero (none), the external trigger is disabled.
768 32072d?04/2011 at32uc3a3/a4 figure 27-4. capture mode timer_clock1 xc 0 xc 1 xc 2 tcclks clki qs r s r q clksta clken clkdis burst tiob capture register a compare rc = 16-bit counter abetrg swtrg etrgedg cpctrg imr trig ldrbs ldras etrgs sr lovrs covfs sync 1 mtiob tioa mtioa ldra ldbstop if ra is not loaded or rb is loaded if ra is loaded ldbdis cpcs int ed g e det ect or ldrb clk ovf reset timer/counter channel edge detector edge detector capture register b register c timer_clock2 timer_clock3 timer_clock4 timer_clock5
769 32072d?04/2011 at32uc3a3/a4 27.6.3 waveform operating mode waveform operating mode is entered by writing a one to the cmrn.wave bit. in waveform operating mode the tc channel generates one or two pwm signals with the same frequency and independently programmable duty cy cles, or generates different types of one- shot or repetitive pulses. in this mode, tioa is configured as an output and tiob is defined as an output if it is not used as an external event. figure 27-5 on page 770 shows the configuration of the tc channel when programmed in waveform operating mode. 27.6.3.1 waveform selection depending on the waveform se lection field in cmrn (cmrn. wavsel), the behavior of cvn varies. with any selection, ra, rb and rc can all be used as compare registers. ra compare is used to control the tioa output, rb compare is used to control the tiob output (if correctly configured) and rc compare is used to control tioa and/or tiob outputs.
770 32072d?04/2011 at32uc3a3/a4 figure 27-5. waveform mode tcclks clki qs r s r q clksta clken clkdis cpcdis burst tiob register a compare rc = cpcstop 16-bit counter eevt eev t e d g sync swtrg en etr g wavsel imr tr i g acpc acpa aeevt aswtrg bcpc bcpb beevt bswtrg tioa mtioa tiob mtiob cpas covfs etrgs sr cpcs cpbs clk ovf reset output contr oller o utput contr oller int 1 edge det ect o r timer/counter channel timer_clock1 xc 0 xc 1 xc 2 wavsel register b register c compare rb = compare ra = timer_clock2 timer_clock3 timer_clock4 timer_clock5
771 32072d?04/2011 at32uc3a3/a4 27.6.3.2 wavsel = 0 when cmrn.wavsel is zero, the value of cv n is incremented fr om 0 to 0xffff. once 0xffff has been reached, the value of cvn is re set. incrementation of cvn starts again and the cycle continues. see figure 27-6 on page 771 . an external event trigger or a software trigger can reset the value of cvn. it is important to note that the trigger may occur at any time. see figure 27-7 on page 772 . rc compare cannot be programmed to generate a trigger in this configuration. at the same time, rc compare can stop the counter clock (cmrn.cpcstop = 1) and/or disable the counter clock (cmrn.cpcdis = 1). figure 27-6. wavsel= 0 without trigger time counter value rc rb ra tiob tioa counter cleared by compare match with 0xffff 0xffff waveform examples
772 32072d?04/2011 at32uc3a3/a4 figure 27-7. wavsel= 0 with trigger 27.6.3.3 wavsel = 2 when cmrn.wavsel is two, the value of cvn is incremented from zero to the value of rc, then automatically reset on a rc compare. once the value of cvn has been reset, it is then incremented and so on. see figure 27-8 on page 773 . it is important to note that cvn can be reset at any time by an external event or a software trig- ger if both are programmed correctly. see figure 27-9 on page 773 . in addition, rc compare can stop the counter clock (cmrn.cpcstop) and/or disable the counter clock (cmrn.cpcdis = 1). time counter value rc rb ra tiob tioa counter cleared by compare match with 0xffff 0xffff waveform examples counter cleared by trigger
773 32072d?04/2011 at32uc3a3/a4 figure 27-8. wavsel = 2 without trigger figure 27-9. wavsel = 2 with trigger 27.6.3.4 wavsel = 1 when cmrn.wavsel is one, the value of cvn is incremented from 0 to 0xffff. once 0xffff is reached, the value of cvn is decremented to 0, then re-incremented to 0xffff and so on. see figure 27-10 on page 774 . time counter value rc rb ra tiob tioa counter cleared by compare match with rc 0xffff waveform examples time counter value r c r b r a tiob tioa counter cleared by compare match with rc 0xffff waveform examples counter cleared by trigger
774 32072d?04/2011 at32uc3a3/a4 a trigger such as an external event or a software trigger can modify cvn at any time. if a trigger occurs while cvn is incrementing, cvn then decrements. if a trigger is received while cvn is decrementing, cvn then increments. see figure 27-11 on page 774 . rc compare cannot be programmed to generate a trigger in this configuration. at the same time, rc compare can stop the counter clock (cmrn.cpcstop = 1) and/or dis- able the counter clock (cmrn.cpcdis = 1). figure 27-10. wavsel = 1 without trigger figure 27-11. wavsel = 1 with trigger time counter value rc rb ra tiob tioa counter decremented by compare match with 0xffff 0xffff waveform examples time counter value tiob tioa counter decremented by compare match with 0xffff 0xffff waveform examples counter decremented by trigger rc rb ra counter incremented by trigger
775 32072d?04/2011 at32uc3a3/a4 27.6.3.5 wavsel = 3 when cmrn.wavsel is three, the value of cvn is incremented from ze ro to rc. once rc is reached, the value of cvn is decremented to zero, then re-incremented to rc and so on. see figure 27-12 on page 775 . a trigger such as an external event or a software trigger can modify cvn at any time. if a trigger occurs while cvn is incrementing, cvn then decrements. if a trigger is received while cvn is decrementing, cvn then increments. see figure 27-13 on page 776 . rc compare can stop the counter clock (cmrn.cp cstop = 1) and/or disable the counter clock (cmrn.cpcdis = 1). figure 27-12. wavsel = 3 without trigger time counter value rc rb ra tiob tioa counter cleared by compare match with rc 0xffff waveform examples
776 32072d?04/2011 at32uc3a3/a4 figure 27-13. wavsel = 3 with trigger 27.6.3.6 external event/trigger conditions an external event can be programmed to be detected on one of the clock sources (xc0, xc1, xc2) or tiob. the external event selected can then be used as a trigger. the external event selection field in cmrn (cmrn.eevt) selects the external trigger. the external event edge selection field in cmrn (cmrn.eevtedg) defines the trigger edge for each of the possible external triggers (rising, fa lling or both). if cmrn.eevtedg is written to zero, no external event is defined. if tiob is defined as an ex ternal event signal (cmrn.eevt = 0), tiob is no longer used as an output and the compare register b is not used to generate waveforms and subsequently no irqs. in this case the tc channel can only generate a waveform on tioa. when an external event is defined, it can be used as a trigger by writing a one to the cmrn.enetrg bit. as in capture mode, the sync signal and the softw are trigger are also available as triggers. rc compare can also be used as a trigger depending on the cmrn.wavsel field. 27.6.3.7 output controller the output controller defines the output level changes on tioa and tiob following an event. tiob control is used only if tiob is defin ed as output (not as an external event). the following events control tioa and tiob: ? software trigger ? external event ? rc compare ra compare controls tioa and rb compare controls tiob. each of these events can be pro- grammed to set, clear or toggle the output as defined in the following fields in cmrn: ? rc compare effect on tiob (cmrn.bcpc) time counter value tiob tioa counter decremented by compare match with rc 0xffff waveform examples rc rb ra counter decremented by trigger counter incremented by trigger
777 32072d?04/2011 at32uc3a3/a4 ? rb compare effect on tiob (cmrn.bcpb) ? rc compare effect on tioa (cmrn.acpc) ? ra compare effect on tioa (cmrn.acpa)
778 32072d?04/2011 at32uc3a3/a4 27.7 user interface table 27-3. tc register memory map offset register register name access reset 0x00 channel 0 control register ccr0 write-only 0x00000000 0x04 channel 0 mode register cmr0 read/write 0x00000000 0x10 channel 0 counter value cv0 read-only 0x00000000 0x14 channel 0 register a ra0 read/write (1) 0x00000000 0x18 channel 0 register b rb0 read/write (1) 0x00000000 0x1c channel 0 register c rc0 read/write 0x00000000 0x20 channel 0 status register sr0 read-only 0x00000000 0x24 interrupt enable register ier0 write-only 0x00000000 0x28 channel 0 interrupt disable register idr0 write-only 0x00000000 0x2c channel 0 interrupt mask register imr0 read-only 0x00000000 0x40 channel 1 control register ccr1 write-only 0x00000000 0x44 channel 1 mode register cmr1 read/write 0x00000000 0x50 channel 1 counter value cv1 read-only 0x00000000 0x54 channel 1 register a ra1 read/write (1) 0x00000000 0x58 channel 1 register b rb1 read/write (1) 0x00000000 0x5c channel 1 register c rc1 read/write 0x00000000 0x60 channel 1 status register sr1 read-only 0x00000000 0x64 channel 1 interrupt enable register ier1 write-only 0x00000000 0x68 channel 1 interrupt disable register idr1 write-only 0x00000000 0x6c channel 1 interrupt mask register imr1 read-only 0x00000000 0x80 channel 2 control register ccr2 write-only 0x00000000 0x84 channel 2 mode register cmr2 read/write 0x00000000 0x90 channel 2 counter value cv2 read-only 0x00000000 0x94 channel 2 register a ra2 read/write (1) 0x00000000 0x98 channel 2 register b rb2 read/write (1) 0x00000000 0x9c channel 2 register c rc2 read/write 0x00000000 0xa0 channel 2 status register sr2 read-only 0x00000000 0xa4 channel 2 interrupt enable register ier2 write-only 0x00000000 0xa8 channel 2 interrupt disable register idr2 write-only 0x00000000 0xac channel 2 interrupt mask register imr2 read-only 0x00000000 0xc0 block control register bcr write-only 0x00000000 0xc4 block mode register bmr read/write 0x00000000 0xf8 features register features read-only - (2) 0xfc version register version read-only - (2)
779 32072d?04/2011 at32uc3a3/a4 notes: 1. read-only if cmrn.wave is zero. 2. the reset values are device specific. please re fer to the module config uration section at the end of this chapter.
780 32072d?04/2011 at32uc3a3/a4 27.7.1 channel control register name: ccr access type: write-only offset: 0x00 + n * 0x40 reset value: 0x00000000 ? swtrg: software trigger command 1: writing a one to this bit will perform a software tr igger: the counter is reset and the clock is started. 0: writing a zero to this bit has no effect. ? clkdis: counter cl ock disable command 1: writing a one to this bit will disable the clock. 0: writing a zero to this bit has no effect. ? clken: counter clock enable command 1: writing a one to this bit will enab le the clock if clkdis is not one. 0: writing a zero to this bit has no effect. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - - - - swtrg clkdis clken
781 32072d?04/2011 at32uc3a3/a4 27.7.2 channel mode register: capture mode name: cmr access type: read/write offset: 0x04 + n * 0x40 reset value: 0x00000000 ? ldrb: rb loading selection ? ldra: ra loading selection ?wave 1: capture mode is disabled (waveform mode is enabled). 0: capture mode is enabled. ? cpctrg: rc compare trigger enable 1: rc compare resets the counter and starts the counter clock. 0: rc compare has no effect on the counter and its clock. ? abetrg: tioa or tiob external trigger selection 1: tioa is used as an external trigger. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - ldrb ldra 15 14 13 12 11 10 9 8 wave cpctrg - - - abetrg etrgedg 76543210 ldbdis ldbstop burst clki tcclks ldrb edge 0 none 1 rising edge of tioa 2 falling edge of tioa 3 each edge of tioa ldra edge 0 none 1 rising edge of tioa 2 falling edge of tioa 3 each edge of tioa
782 32072d?04/2011 at32uc3a3/a4 0: tiob is used as an external trigger. ? etrgedg: external trigger edge selection ? ldbdis: counter clock disable with rb loading 1: counter clock is disabled when rb loading occurs. 0: counter clock is not disabled when rb loading occurs. ? ldbstop: counter clock stopped with rb loading 1: counter clock is stopped when rb loading occurs. 0: counter clock is not stopped when rb loading occurs. ? burst: burst signal selection ? clki: clock invert 1: the counter is incremented on falling edge of the clock. 0: the counter is incremented on rising edge of the clock. ? tcclks: clock selection etrgedg edge 0 none 1 rising edge 2 falling edge 3 each edge burst burst signal selection 0 the clock is not gated by an external signal 1 xc0 is anded with the selected clock 2 xc1 is anded with the selected clock 3 xc2 is anded with the selected clock tcclks clock selected 0timer_clock1 1timer_clock2 2timer_clock3 3timer_clock4 4timer_clock5 5xc0 6xc1 7xc2
783 32072d?04/2011 at32uc3a3/a4 27.7.3 channel mode re gister: waveform mode name: cmr access type: read/write offset: 0x04 + n * 0x40 reset value: 0x00000000 ? bswtrg: software trigger effect on tiob ? beevt: external event effect on tiob 31 30 29 28 27 26 25 24 bswtrg beevt bcpc bcpb 23 22 21 20 19 18 17 16 aswtrg aeevt acpc acpa 15 14 13 12 11 10 9 8 wave wavsel enetrg eevt eevtedg 76543210 cpcdis cpcstop burst clki tcclks bswtrg effect 0 none 1set 2clear 3 toggle beevt effect 0 none 1set 2clear 3 toggle
784 32072d?04/2011 at32uc3a3/a4 ? bcpc: rc compare effect on tiob ? bcpb: rb compare effect on tiob ? aswtrg: software trigger effect on tioa ? aeevt: external event effect on tioa ? acpc: rc compare effect on tioa bcpc effect 0 none 1set 2clear 3 toggle bcpb effect 0 none 1set 2clear 3 toggle aswtrg effect 0 none 1set 2clear 3 toggle aeevt effect 0 none 1set 2clear 3 toggle acpc effect 0 none 1set 2clear 3 toggle
785 32072d?04/2011 at32uc3a3/a4 ? acpa: ra compare effect on tioa ?wave 1: waveform mode is enabled. 0: waveform mode is disabled (capture mode is enabled). ? wavsel: waveform selection ? enetrg: external event trigger enable 1: the external event resets the counter and starts the counter clock. 0: the external event has no effect on the counter and its clock. in this case, the selected external event only controls the t ioa output. ? eevt: external event selection note: 1. if tiob is chosen as the external event signal, it is conf igured as an input and no longer generates waveforms and subse- quently no irqs . ? eevtedg: external ev ent edge selection ? cpcdis: counter clock disable with rc compare 1: counter clock is disabled when counter reaches rc. 0: counter clock is not disabled when counter reaches rc. acpa effect 0 none 1set 2clear 3 toggle wavsel effect 0 up mode without automatic trigger on rc compare 1 updown mode without automat ic trigger on rc compare 2 up mode with automatic trigger on rc compare 3 updown mode with automatic trigger on rc compare eevt signal selected as exte rnal event tiob direction 0 tiob input (1) 1 xc0 output 2 xc1 output 3 xc2 output eevtedg edge 0none 1 rising edge 2 falling edge 3 each edge
786 32072d?04/2011 at32uc3a3/a4 ? cpcstop: counter clock stopped with rc compare 1: counter clock is stopped when counter reaches rc. 0: counter clock is not stopped when counter reaches rc. ? burst: burst signal selection ? clki: clock invert 1: counter is incremented on falling edge of the clock. 0: counter is incremented on rising edge of the clock. ? tcclks: clock selection burst burst signal selection 0 the clock is not gated by an external signal. 1 xc0 is anded with the selected clock. 2 xc1 is anded with the selected clock. 3 xc2 is anded with the selected clock. tcclks clock selected 0timer_clock1 1timer_clock2 2timer_clock3 3timer_clock4 4timer_clock5 5xc0 6xc1 7xc2
787 32072d?04/2011 at32uc3a3/a4 27.7.4 channel counter value register name: cv access type: read-only offset: 0x10 + n * 0x40 reset value: 0x00000000 ?cv: counter value cv contains the counter value in real time. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 cv[15:8] 76543210 cv[7:0]
788 32072d?04/2011 at32uc3a3/a4 27.7.5 channel register a name: ra access type: read-only if cmrn.wave = 0, read/write if cmrn.wave = 1 offset: 0x14 + n * 0x40 reset value: 0x00000000 ? ra: register a ra contains the register a value in real time. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 ra[15:8] 76543210 ra[7:0]
789 32072d?04/2011 at32uc3a3/a4 27.7.6 channel register b name: rb access type: read-only if cmrn.wave = 0, read/write if cmrn.wave = 1 offset: 0x18 + n * 0x40 reset value: 0x00000000 ? rb: register b rb contains the register b value in real time. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 rb[15:8] 76543210 rb[7:0]
790 32072d?04/2011 at32uc3a3/a4 27.7.7 channel register c name: rc access type: read/write offset: 0x1c + n * 0x40 reset value: 0x00000000 ? rc: register c rc contains the register c value in real time. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 rc[15:8] 76543210 rc[7:0]
791 32072d?04/2011 at32uc3a3/a4 27.7.8 channel status register name: sr access type: read-only offset: 0x20 + n * 0x40 reset value: 0x00000000 note: reading the status register will also clear th e interrupt bit for the co rresponding interrupts. ? mtiob: tiob mirror 1: tiob is high. if cmrn.wave is zero, this means that tiob pi n is high. if cmrn.wave is one, this means that tiob is driven high. 0: tiob is low. if cmrn.wave is zero, this means that tiob pi n is low. if cmrn.wave is one, this means that tiob is driven low. ? mtioa: tioa mirror 1: tioa is high. if cmrn.wave is zero, this means that tioa pin is high. if cmrn.wave is one, th is means that tioa is driven high. 0: tioa is low. if cmrn.wave is zero, this means that tioa pin is low. if cmrn.wave is one, this means that tioa is driven low. ? clksta: clock enabling status 1: this bit is set when the clock is enabled. 0: this bit is cleared when the clock is disabled. ? etrgs: external trigger status 1: this bit is set when an external trigger has occurred. 0: this bit is cleared when the sr register is read. ? ldrbs: rb loading status 1: this bit is set when an rb load has occurred and cmrn.wave is zero. 0: this bit is cleared when the sr register is read. ? ldras: ra loading status 1: this bit is set when an ra load has occurred and cmrn.wave is zero. 0: this bit is cleared when the sr register is read. ? cpcs: rc compare status 1: this bit is set when an rc compare has occurred. 0: this bit is cleared when the sr register is read. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - - mtiob mtioa clksta 15 14 13 12 11 10 9 8 -------- 76543210 etrgs ldrbs ldras cpcs cpbs cpas lovrs covfs
792 32072d?04/2011 at32uc3a3/a4 ? cpbs: rb compare status 1: this bit is set when an rb compare has occurred and cmrn.wave is one. 0: this bit is cleared when the sr register is read. ? cpas: ra compare status 1: this bit is set when an ra compare has occurred and cmrn.wave is one. 0: this bit is cleared when the sr register is read. ? lovrs: load overrun status 1: this bit is set when ra or rb have been loaded at l east twice without any read of the corresponding register and cmrn.wave is zero. 0: this bit is cleared when the sr register is read. ? covfs: counter overflow status 1: this bit is set when a counter overflow has occurred. 0: this bit is cleared when the sr register is read.
793 32072d?04/2011 at32uc3a3/a4 27.7.9 channel interrupt enable register name: ier access type: write-only offset: 0x24 + n * 0x40 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will set the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 etrgs ldrbs ldras cpcs cpbs cpas lovrs covfs
794 32072d?04/2011 at32uc3a3/a4 27.7.10 channel interrupt disable register name: idr access type: write-only offset: 0x28 + n * 0x40 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 etrgs ldrbs ldras cpcs cpbs cpas lovrs covfs
795 32072d?04/2011 at32uc3a3/a4 27.7.11 channel interrupt mask register name: imr access type: read-only offset: 0x2c + n * 0x40 reset value: 0x00000000 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. a bit in this register is cleared when the corresponding bit in idr is written to one. a bit in this register is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 etrgs ldrbs ldras cpcs cpbs cpas lovrs covfs
796 32072d?04/2011 at32uc3a3/a4 27.7.12 block control register name: bcr access type: write-only offset: 0xc0 reset value: 0x00000000 ? sync: synchro command 1: writing a one to this bit asserts the sync signal which generates a software trigger simultaneously for each of the channels . 0: writing a zero to this bit has no effect. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -------sync
797 32072d?04/2011 at32uc3a3/a4 27.7.13 block mode register name: bmr access type: read/write offset: 0xc4 reset value: 0x00000000 ? tc2xc2s: external clock signal 2 selection ? tc1xc1s: external clock signal 1 selection 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - tc2xc2s tc1xc1s tc0xc0s tc2xc2s signal connected to xc2 0tclk2 1none 2tioa0 3tioa1 tc1xc1s signal connected to xc1 0tclk1 1none 2tioa0 3tioa2
798 32072d?04/2011 at32uc3a3/a4 ? tc0xc0s: external cloc k signal 0 selection tc0xc0s signal connected to xc0 0tclk0 1none 2tioa1 3tioa2
799 32072d?04/2011 at32uc3a3/a4 27.7.14 features register name: features access type: read-only offset: 0xf8 reset value: - ? brpbhsb: bridge type is pb to hsb 1: bridge type is pb to hsb. 0: bridge type is not pb to hsb. ? updnimpl: up/down is implemented 1: up/down counter capability is implemented. 0: up/down counter capability is not implemented. ? ctrsize: counter size this field indicates the size of the counter in bits. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ------- 15 14 13 12 11 10 9 8 - - - - - - brpbhsb updnimpl 76543210 ctrsize
800 32072d?04/2011 at32uc3a3/a4 27.7.15 version register name: version access type: read-only offset: 0xfc reset value: - ? variant: variant number reserved. no functionality associated. ? version: version number version number of the module. no functionality associated. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ---- variant 15 14 13 12 11 10 9 8 - - - - version[11:8] 76543210 version[7:0]
801 32072d?04/2011 at32uc3a3/a4 27.8 module configuration the specific configuration for each tc instance is listed in the following tables.the module bus clocks listed here are connected to the system bus clocks according to the table in the power manager section. 27.8.1 clock connections each timer/counter channel can independently select an internal or external clock source for its counter: table 27-4. module clock name module name clock name tc0 clk_tc0 tc1 clk_tc1 table 27-5. timer/counter intern al clock connections name connection timer_clock1 32 khz clock timer_clock2 pba clock / 2 timer_clock3 pba clock / 8 timer_clock4 pba clock / 32 timer_clock5 pba clock / 128
802 32072d?04/2011 at32uc3a3/a4 28. analog-to-digital converter (adc) rev: 2.0.0.1 28.1 features ? integrated multiplexer offering up to eight independent analog inputs ? individual enable and disable of each channel ? hardware or software trigger ? external trigger pin ?timer counter outputs (corresponding tioa trigger) ? peripheral dma controller support ? possibility of adc timings configuration ? sleep mode and conversion sequencer ? automatic wakeup on trigger and back to sleep mode after conversions of all enabled channels 28.2 overview the analog-to-digital converter (adc) is based on a successive approximation register (sar) 10-bit adc. it also integrates an 8-to-1 analog multiplexer, making possible the analog-to-digital conversions of 8 analog lines. the conversions extend from 0v to vddana. the adc supports an 8-bit or 10-bit resolution mode, and conversion results are reported in a common register for all channels, as well as in a channel-dedicated register. software trigger, external trigger on rising edge of the trigger pin, or internal triggers from timer counter out- put(s) are configurable. the adc also integrates a sleep mode and a co nversion sequencer and connects with a periph- eral dma controller channel. these features reduce both power consumption and processor intervention. finally, the user can configure adc timings, such as startup time and sample & hold time.
803 32072d?04/2011 at32uc3a3/a4 28.3 block diagram figure 28-1. adc block diagram 28.4 i/o lines description 28.5 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 28.5.1 i/o lines the trigger pin may be shared with other peripheral functions through the i/o controller. table 28-1. adc pins description pin name description vddana analog power supply ad[0] - ad[ 7] analog input channels trigger external trigger ad- ad- ad- dedicated analog inputs ad- ad- ad- analog inputs multiplexed with i/o lines gnd vddana trigger trigger selection vref successive approximation register analog-to-digital converter user interface control logic adc timer counter channels adc interrupt interrupt controller peripheral dma controller high speed bus (hsb) peripheral bridge peripheral bus (pb) i/o controller
804 32072d?04/2011 at32uc3a3/a4 28.5.2 power management in sleep mode, the adc clock is automatically stopped after each conversion. as the logic is small and the adc cell can be put into sleep mode, the power manager has no effect on the adc behavior. 28.5.3 clocks the clock for the adc bus interface (clk_adc) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to disable the adc before disabling the clock, to avoid freezing the adc in an undefined state. the clk_adc clock frequency must be in line wit h the adc characteritics. refer to electrical characteristics se ction for details. 28.5.4 interrupts the adc interrupt request line is connected to t he interrupt controller. using the adc interrupt requires the interrupt controller to be programmed first. 28.5.5 analog inputs the analog input pins can be multiplexed with i/o lines. in this case, the assignment of the adc input is automatically done as soon as the corre sponding i/o is configured through the i/o con- toller. by default, after reset, the i/o line is configured as a logic input. 28.5.6 timer triggers timer counters may or may not be used as hardware triggers depending on user requirements. thus, some or all of the timer counters may be non-connected. 28.6 functional description 28.6.1 analog-to-digital conversion the adc uses the adc clock to perform conversi ons. converting a single analog value to a 10- bit digital data requires sample and hold clock cycles as defined in the sample and hold time field of the mode register (mr.shtim) and 10 adc clock cycles. the adc clock frequency is selected in the prescaler ra te selection field of the mr register (mr.prescal). the adc clock range is between clk_adc/2, if the prescal field is 0, and clk_adc/128, if the prescal field is 63 (0x3f). the prescal field must be written in order to provide an adc clock frequency according to the parameters given in the electrical characteristics chapter. 28.6.2 conversion reference the conversion is performed on a full range between 0v and the reference voltage connected to vddana. analog input values between these volt ages are converted to digital values based on a linear conversion. 28.6.3 conversion resolution the adc supports 8-bit or 10-bit resolutions. the 8-bit selection is performed by writing a one to the resolution bit in the mr register (mr.lowres). by default, after a reset, the resolution is the highest and the converted data field in the channel data registers (cdrn.data) is fully used. by writing a one to the lowres bit, the adc switches in the lowest resolution and the conversion results can be read in the eight lowest significant bits of the channel data registers (cdrn). the two highest bits of the data field in the corresponding cdrn register will be read
805 32072d?04/2011 at32uc3a3/a4 as zero. the two highest bits of the last data converted field in the last converted data regis- ter (lcdr.ldata) will be read as zero too. moreover, when a peripheral dma channel is connected to the adc, a 10-bit resolution sets the transfer request size to 16-bit. writing a one to t he lowres bit automatically switches to 8-bit data transfers. in this case, the destination buffers are optimized. 28.6.4 conversion results when a conversion is completed, the resulting 10-b it digital value is stored in the cdr register of the current channel and in the lcdr register. channels are enabled by writing a one to the channel n enable bit (chn) in the cher register. the corresponding channel end of conversion bit in the status register (sr.eocn) and the data ready bit in the sr register (sr.drdy) are set. in the case of a connected peripheral dma channel, drdy rising trigge rs a data transfer request. in any case, either eoc or drdy can trigger an interrupt. reading one of the cdrn registers clears the corresponding eoc bit. reading lcdr clears the drdy bit and the eoc bit corresponding to the last converted channel. figure 28-2. eocn and drdy flag behavior read lcdr write cr with start=1 read cdrn write cr with start=1 chn(chsr) eocn(sr) drdy(sr) conversion time conversion time
806 32072d?04/2011 at32uc3a3/a4 if the cdr register is not read before further incoming data is converted, the corresponding overrun error bit in the sr register (sr.ovren) is set. in the same way, new data converted when drdy is high sets the general overrun error bit in the sr register (sr.govre). the ovren and govre bits are automatically cleared when the sr register is read. figure 28-3. govre and ovren flag behavior warning: if the corresponding channel is disabled during a conversion or if it is disabled and then reenabled during a conversion, its associated data and its corresponding eoc and ovre flags in sr are unpredictable. read sr data c data c data b data b data a data a undefined data undefined data undefined data lcdr crd0 ch1(chsr) ch0(chsr) trigger crd1 eoc0(sr) eoc1(sr) govre(sr) drdy(asr) ovre0(sr) read cdr0 read cdr1 conversion conversion conversion
807 32072d?04/2011 at32uc3a3/a4 28.6.5 conversion triggers conversions of the active analog channels are started with a software or a hardware trigger. the software trigger is provided by writing a one to the start bit in the control register (cr.start). the hardware trigger can be one of the tioa outputs of the timer counter channels, or the external trigger input of the adc (trigger). t he hardware trigger is selected with the trigger selection field in the mode register (mr.trigsel). the selected hardware trigger is enabled by writing a one to the trigger enable bit in the mode register (mr.trgen). if a hardware trigger is selected, the start of a c onversion is detected at each rising edge of the selected signal. if one of the tioa outputs is selected, the corresponding timer counter channel must be programmed in waveform mode. only one start command is necessary to initiate a conversion sequence on all the channels. the adc hardware logic automatically performs the conversions on the active channels, then waits for a new request. the channel enable (cher) and channel disable (chdr) registers enable the analog channels to be enabled or disabled independently. if the adc is used with a peripheral dma controller, only the transfers of converted data from enabled channels are performed and the resulting data buffers should be interpreted accordingly. warning: enabling hardware triggers does not disable the software trigger functionality. thus, if a hardware trigger is selected, the start of a conversion can be initiated either by the hardware or the software trigger. 28.6.6 sleep mode and conversion sequencer the adc sleep mode maximizes power saving by automatically deactivating the adc when it is not being used for conversions. sleep mode is se lected by writing a one to the sleep mode bit in the mode register (mr.sleep). the sleep mode is automatically managed by a conversion sequencer, which can automati- cally process the conversions of all channels at lowest power consumption. when a start conversion request occurs, the adc is automatically activated. as the analog cell requires a start-up time, the logic waits during this time and starts the conversion on the enabled channels. when all conversions are complete, the adc is deactivated until the next trigger. trig- gers occurring during the sequence are not taken into account. the conversion sequencer allows automatic pr ocessing with minimum processor intervention and optimized power consumption. conversion sequences can be performed periodically using a timer/counter output. the periodic acquisition of several samples can be processed automat- ically without any intervention of the processor thanks to the peripheral dma controller. note: the reference voltage pins always remain connected in normal mode as in sleep mode.
808 32072d?04/2011 at32uc3a3/a4 28.6.7 adc timings each adc has its own minimal startup time that is defined through the start up time field in the mode register (mr.startup). this startup time is given in the electrical characteristics chapter. in the same way, a minimal sample and hold time is necessary for the adc to guarantee the best converted final value between two channels selection. this time has to be defined through the sample and hold time field in the mode register (mr.shtim). this time depends on the input impedance of the analog input, but also on the output impedance of the driver providing the signal to the analog input, as there is no input buffer amplifier. 28.6.8 conversion performances for performance and electrical characteristics of the adc, see the electrical characteristics chapter.
809 32072d?04/2011 at32uc3a3/a4 28.7 user interface note: 1. the reset values are device specific. please refer to the module configuration section at the end of this chapter. table 28-2. adc register memory map offset register name access reset state 0x00 control register cr write-only 0x00000000 0x04 mode register mr read/write 0x00000000 0x10 channel enable register cher write-only 0x00000000 0x14 channel disable register chdr write-only 0x00000000 0x18 channel status register chsr read-only 0x00000000 0x1c status register sr read-only 0x000c0000 0x20 last converted data register lcdr read-only 0x00000000 0x24 interrupt enable register ier write-only 0x00000000 0x28 interrupt disable register idr write-only 0x00000000 0x2c interrupt mask register imr read-only 0x00000000 0x30 channel data register 0 cdr0 read-only 0x00000000 ... ...(if implemented) ... ... ... 0x4c channel data register 7(if implemented) cdr 7 read-only 0x00000000 0xfc version register version read-only - (1)
810 32072d?04/2011 at32uc3a3/a4 28.7.1 control register name: cr access type: write-only offset: 0x00 reset value: 0x00000000 ? start: start conversion writing a one to this bit will begin an analog-to-digital conversion. writing a zero to this bit has no effect. this bit always reads zero. ? swrst: software reset writing a one to this bit will reset the adc. writing a zero to this bit has no effect. this bit always reads zero. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????startswrst
811 32072d?04/2011 at32uc3a3/a4 28.7.2 mode register name: mr access type: read/write offset: 0x04 reset value: 0x00000000 ? shtim: sample & hold time sample & hold time = (shtim+3) / adcclock ? startup: start up time startup time = (startup+1) * 8 / adcclock this time should respect a minimal value. refer to electrical characteristics section for details. ? prescal: prescaler rate selection adcclock = clk_adc / ( (prescal+1) * 2 ) ? sleep: sleep mode 1: sleep mode is selected. 0: normal mode is selected. ? lowres: resolution 1: 8-bit resolution is selected. 0: 10-bit resolution is selected. ? trgsel: trigger selection ? trgen: trigger enable 1: the hardware trigger selected by the trgsel field is enabled. 0: the hardware triggers are disabled. starting a conversion is only possible by software. 31 30 29 28 27 26 25 24 ???? shtim 23 22 21 20 19 18 17 16 ?startup 15 14 13 12 11 10 9 8 prescal 76543210 ? ? sleep lowres trgsel trgen trgsel selected trgsel 0 0 0 internal trigger 0, depending of chip integration 0 0 1 internal trigger 1, depending of chip integration 0 1 0 internal trigger 2, depending of chip integration 0 1 1 internal trigger 3, depending of chip integration 1 0 0 internal trigger 4, depending of chip integration 1 0 1 internal trigger 5, depending of chip integration 1 1 0 external trigger
812 32072d?04/2011 at32uc3a3/a4 28.7.3 channel enable register name: cher access type: write-only offset: 0x10 reset value: 0x00000000 ? chn: channel n enable writing a one to these bits will set the corresponding bit in chsr. writing a zero to these bits has no effect. these bits always read a zero. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ch7 ch6 ch5 ch4 ch3 ch2 ch1 ch0
813 32072d?04/2011 at32uc3a3/a4 28.7.4 channel disable register name: chdr access type: write-only offset: 0x14 reset value: 0x00000000 ? chn: channel n disable writing a one to these bits will clear the corresponding bit in chsr. writing a zero to these bits has no effect. these bits always read a zero. warning: if the corresponding channel is disabled during a conversion or if it is disabled then reenabled during a conversion, its associated data and its corresponding eoc and ovre flags in sr are unpredictable. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ch7 ch6 ch5 ch4 ch3 ch2 ch1 ch0
814 32072d?04/2011 at32uc3a3/a4 28.7.5 channel status register name: chsr access type: read-only offset: 0x18 reset value: 0x00000000 ? chn: channel n status these bits are set when the corresponding bits in cher is written to one. these bits are cleared when the corresponding bits in chdr is written to one. 1: the corresponding channel is enabled. 0: the corresponding channel is disabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ch7 ch6 ch5 ch4 ch3 ch2 ch1 ch0
815 32072d?04/2011 at32uc3a3/a4 28.7.6 status register name: sr access type: read-only offset: 0x1c reset value: 0x000c0000 ? rxbuff: rx buffer full this bit is set when the buffer full signal from the peripheral dma is active. this bit is cleared when the buffer full signal from the receive peripheral dma is inactive. ? endrx: end of rx buffer this bit is set when the end receive signal from the peripheral dma is active. this bit is cleared when the end receive signal from the peripheral dma is inactive. ? govre: general overrun error this bit is set when a general overrun error has occurred. this bit is cleared when the sr register is read. 1: at least one general overrun error has occu rred since the last read of the sr register. 0: no general overrun error occurred since the last read of the sr register. ? drdy: data ready this bit is set when a data has been converted and is available in the lcdr register. this bit is cleared when the lcdr register is read. 0: no data has been converted since the last read of the lcdr register. 1: at least one data has been converted and is available in the lcdr register. ? ovren: overrun error n these bits are set when an overrun error on the corresponding channel has occurred (if implemented). these bits are cleared when the sr register is read. 0: no overrun error on the corresponding channel (if implemented) since the last read of sr. 1: there has been an overrun error on the corresponding channel (if implemented) since the last read of sr. ? eocn: end of conversion n these bits are set when the corresponding conversion is complete. these bits are cleared when the corresponding cdr or lcdr registers are read. 0: corresponding analog channel (if implemented) is disabled, or the conversion is not finished. 1: corresponding analog channel (if implemented) is enabled and conversion is complete. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ????rxbuffendrxgovredrdy 15 14 13 12 11 10 9 8 ovre7 ovre6 ovre5 ovre4 ovre3 ovre2 ovre1 ovre0 76543210 eoc7 eoc6 eoc5 eoc4 eoc3 eoc2 eoc1 eoc0
816 32072d?04/2011 at32uc3a3/a4 28.7.7 last converted data register name: lcdr access type: read-only offset: 0x20 reset value: 0x00000000 ? ldata: last data converted the analog-to-digital conversion data is placed into this regist er at the end of a conversion and remains until a new conversio n is completed. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ?????? ldata[9:8] 76543210 ldata[7:0]
817 32072d?04/2011 at32uc3a3/a4 28.7.8 interrupt enable register name: ier access type: write-only offset: 0x24 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will set the corresponding bit in imr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ????rxbuffendrxgovredrdy 15 14 13 12 11 10 9 8 ovre7 ovre6 ovre5 ovre4 ovre3 ovre2 ovre1 ovre0 76543210 eoc7 eoc6 eoc5 eoc4 eoc3 eoc2 eoc1 eoc0
818 32072d?04/2011 at32uc3a3/a4 28.7.9 interrupt disable register name: idr access type: write-only offset: 0x28 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in imr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ????rxbuffendrxgovredrdy 15 14 13 12 11 10 9 8 ovre7 ovre6 ovre5 ovre4 ovre3 ovre2 ovre1 ovre0 76543210 eoc7 eoc6 eoc5 eoc4 eoc3 eoc2 eoc1 eoc0
819 32072d?04/2011 at32uc3a3/a4 28.7.10 interrupt mask register name: imr access type: read-only offset: 0x2c reset value: 0x00000000 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. a bit in this register is cleared when the corresponding bit in idr is written to one. a bit in this register is cleared when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ????rxbuffendrxgovredrdy 15 14 13 12 11 10 9 8 ovre7 ovre6 ovre5 ovre4 ovre3 ovre2 ovre1 ovre0 76543210 eoc7 eoc6 eoc5 eoc4 eoc3 eoc2 eoc1 eoc0
820 32072d?04/2011 at32uc3a3/a4 28.7.11 channel data register name: cdrx access type: read-only offset: 0x2c-0x4c reset value: 0x00000000 ? data: converted data the analog-to-digital conversion data is placed into this regist er at the end of a conversion and remains until a new conversio n is completed. the convert data register (cdr) is only loaded if the corresponding analog channel is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ?????? data[9:8] 76543210 data[7:0]
821 32072d?04/2011 at32uc3a3/a4 28.7.12 version register name: version access type: read-only offset: 0xfc reset value: ? ? variant: variant number reserved. no functionality associated. ? version: version number version number of the module. no functionality associated. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???? variant 15 14 13 12 11 10 9 8 ???? version[11:8] 76543210 version[7:0]
822 32072d?04/2011 at32uc3a3/a4 28.8 module configuration the specific configuration for the adc in stance is listed in the following tables. table 28-3. module configuration feature adc adc_num_channels 8 internal trigger 0 tioa ouput a of the timer counter 0 channel 0 internal trigger 1 tiob ouput b of the timer counter 0 channel 0 internal trigger 2 tioa ouput a of the timer counter 0 channel 1 internal trigger 3 tiob ouput b of the timer counter 0 channel 1 internal trigger 4 tioa ouput a of the timer counter 0 channel 2 internal trigger 5 tiob ouput b of the timer counter 0 channel 2 table 28-4. module clock name module name clock name adc clk_adc table 28-5. register reset values module name reset value version 0x00000200
823 32072d?04/2011 at32uc3a3/a4 29. hsb bus performance monitor (busmon) rev 1.0.0.0 29.1 features ? allows performance monitoring of high speed bus master interfaces ? up to 4 masters can be monitored ? peripheral bus access to monitor registers ? the following is monitored ? data transfer cycles ? bus stall cycles ? maximum access latency for a single transfer ? automatic handling of event overflow 29.2 overview busmon allows the user to measure the activity and stall cycles on the high speed bus (hsb). up to 4 device-specific masters can be measured. each of these masters is part of a measure- ment channel. which masters that are connected to a channel is device-specific. devices may choose not to implement all channels. 29.3 block diagram figure 29-1. busmon block diagram registers master a master b master c master d slave 0 registers master e master f master g master h slave 1 registers master i master j master k master l slave 2 registers master m master n master o master p slave 3 control peripheral bus interface channel 0 channel 1 channel 2 channel 3
824 32072d?04/2011 at32uc3a3/a4 29.4 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 29.4.1 clocks the clock for the busmon bus interface (clk_busmon) is generated by the power manager. this clock is enabled at reset and can be disabled in the power manager. it is recommended to disable the busmon before disabling the clock, to avoid freezing the busmon in an undefined state. 29.5 functional description three different parameters can be measured by each channel: ? the number of data transfer cycles since last channel reset ? the number of stall cycles since last channel reset ? the maximum continuous number of stall cycles since last channel reset (this approximates the max latency in the transfers.) these measurements can be extracted by soft ware and used to generate indicators for bus latency, bus load and maximum bus latency. each of the counters have a fixed width, and ma y therefore overflow. when overflow is encoun- tered in either the channel n data cycles (d atan) register or the channel n stall cycles (stalln) register of a channel, all registers in the channel are reset. this behavior is altered if the channel n overflow freeze (chnof) bit is se t in the control (control) register. if this bit is written to one, the channel registers are frozen when either datan or stalln reaches its maximum value. this simplifies one-shot readout of the counter values. the registers can also be manually reset by writing to the control register. the channeln max initiation latency (latn) regi ster is saturating, when its max count is reached, it will be set to its maximum value. the latn register is reset whenever datan and stalln are reset. a counter must manually be enabled by writing to the control register.
825 32072d?04/2011 at32uc3a3/a4 29.6 user interface note: 1. the reset values are device specific. please refer to the module configuration section at the end of this chapter. table 29-1. busmon register memory map offset register register name access reset 0x00 control register cont rol read/write 0x00000000 0x10 channel0 data cycles register data0 read 0x00000000 0x14 channel0 stall cycles register stall0 read 0x00000000 0x18 channel0 max initiation latency register lat0 read 0x00000000 0x20 channel1 data cycles register data1 read 0x00000000 0x24 channel1 stall cycles register stall1 read 0x00000000 0x28 channel1 max initiation latency register lat1 read 0x00000000 0x30 channel2 data cycles register data2 read 0x00000000 0x34 channel2 stall cycles register stall2 read 0x00000000 0x38 channel2 max initiation latency register lat2 read 0x00000000 0x40 channel3 data cycles register data3 read 0x00000000 0x44 channel3 stall cycles register stall3 read 0x00000000 0x48 channel3 max initiation latency register lat3 read 0x00000000 0x50 parameter register parameter read - (1) 0x54 version register version read - (1)
826 32072d?04/2011 at32uc3a3/a4 29.6.1 control register name: control access type: read/write offset: 0x00 reset value: 0x00000000 ? chnres: channe l counter reset writting a one to this bit will reset the counter in the channel n. writting a zero to this bit has no effect. this bit always reads as zero. ? chnof: channel overflow freeze 1: all channel n registers are frozen just before data or stall overflows. 0: the channel n registers are reset if data or stall overflows. ? chnen: channel enabled 1: the channel n is enabled. 0: the channel n is disabled. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ----ch3resch2resch1resch0res 15 14 13 12 11 10 9 8 ----ch3ofch2ofch1ofch0of 76543210 -- --ch3ench2ench1ench0en
827 32072d?04/2011 at32uc3a3/a4 29.6.2 channel n data cycles register name: datan access type: read-only offset: 0x10 + n*0x10 reset value: 0x00000000 ?data: data cycles counted since the last reset. 31 30 29 28 27 26 25 24 data[31:24] 23 22 21 20 19 18 17 16 data[23:16] 15 14 13 12 11 10 9 8 data[15:8] 76543210 data[7:0]
828 32072d?04/2011 at32uc3a3/a4 29.6.3 channel n sta ll cycles register name: stalln access type: read-only offset: 0x14 + n*0x10 reset value: 0x00000000 ?stall: stall cycles counted since the last reset. 31 30 29 28 27 26 25 24 stall[31:24] 23 22 21 20 19 18 17 16 stall[23:16] 15 14 13 12 11 10 9 8 stall[15:8] 76543210 stall[7:0]
829 32072d?04/2011 at32uc3a3/a4 29.6.4 channel n max transfer initiation cycles register name: latn access type: read-only offset: 0x18 + n*0x10 reset value: 0x00000000 ?lat: this field is cleared whenever the data or stall register is reset. maximum transfer initiation cyc les counted since the last reset. this counter is saturating. 31 30 29 28 27 26 25 24 lat[31:24] 23 22 21 20 19 18 17 16 lat[23:16] 15 14 13 12 11 10 9 8 lat[15:8] 76543210 lat[7:0]
830 32072d?04/2011 at32uc3a3/a4 29.6.5 parameter register name: parameter access type: read-only offset: 0x50 reset value: - ? chnimp: channel implementation 1: the corresponding channel is implemented. 0: the corresponding channel is not implemented. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - - - ch3impl ch2impl ch1impl ch0impl
831 32072d?04/2011 at32uc3a3/a4 29.6.6 version register name: version access type: read-only offset: 0x54 reset value: - ? variant: variant number reserved. no functionality associated. ? version: version number version number of the module. no functionality associated. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ---- variant 15 14 13 12 11 10 9 8 - - - - version[11:8] 76543210 version[7:0]
832 32072d?04/2011 at32uc3a3/a4 29.7 module configuration table 29-2. register reset values register reset value version 0x00000100 parameter 0x0000000f
833 32072d?04/2011 at32uc3a3/a4 30. multimedia card interface (mci) rev. 4.1.0.0 30.1 features ? compatible with multimedia card specification version 4.3 ? compatible with sd memory card specification version 2.0 ? compatible with sdio specification version 1.1 ? compatible with ce-ata specification 1.1 ? cards clock rate up to master clock divided by two ? boot operation mode support ? high speed mode support ? embedded power management to slow down clock rate when not used ? supports 2 ? each slot for either a multimediacard bus (up to 30 cards) or an sd memory card ? support for stream, block and multi-block data read and write ? supports connection to dma controller ? minimizes processor intervention for large buffer transfers ? built in fifo (from 16 to 256 bytes) with larg e memory aperture supporting incremental access ? support for ce-ata completi on cignal disable command ? protection against unexpected modification on-the-fly of the configuration registers 30.2 overview the multimedia card interface (mci) supports t he multimedia card (mmc) specification v4.3, the sd memory card specification v2.0, the sd io v1.1 specificationand ce-ata specification v1.1. the mci includes a command register (cmdr), response registers (r sprn), data registers, time-out counters and error detection logic that automatically handle the transmission of com- mands and, when required, the reception of the associated responses and data with a limited processor overhead. the mci supports stream, block and multi block data read and write, and is compatible with the dma controller, minimizing processor intervention for large buffers transfers. the mci operates at a rate of up to clk_mci divided by 2 and supports the interfacing of 2. each slot may be used to interface with a multimediacard bus (up to 30 cards) or with a sd memory card. only one slot can be selected at a time (slots are multiplexed). the sdcard/sdio slot selection field in the sdcard/sdio register (sdcr.sdcsel) performs this selection. the sd memory card communication is based on a 9-pin interface (clock, command, four data and three power lines) and the multimedia card on a 7-pin to 13-pin nterface (clock, command, one to eight data, three power lines and one reserved for future use). the sd memory card interface also supports multimedia card operations. the main differences between sd and multimedia cards are the initialization process and the bus topology. mci fully supports ce-ata revision 1.1, built on the mmc system specification v4.0. the mod- ule includes dedicated hardware to issue the co mmand completion signal and capture the host command completion signal disable.
834 32072d?04/2011 at32uc3a3/a4 30.3 block diagram figure 30-1. mci block diagram figure 30-2. application block diagram cmd clk data i/o controller dma controller mci interface interrupt control mci interrupt clk_mci power manager peripheral bus peripheral bus brigde 1 2 3 4 5 6 mmc 7 1 9 2 345 7 68 sdcard physical layer mci interface application layer ex: file system, audio, security, etc 9 10 1213 8
835 32072d?04/2011 at32uc3a3/a4 30.4 i/o lines description 30.5 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 30.5.1 power management if the cpu enters a sleep mode th at disables clocks used by t he mci, the mci will stop function- ing and resume operation after the system wakes up from sleep mode. 30.5.2 i/o lines the pins used for interfacing the multimedia ca rds or sd cards may be multiplexed with gpio lines. user must first program the i/o controller to assign the peripheral functions to mci pins. 30.5.3 clocks the clock for the mci bus interface (clk_mci) is generated by the power manager. this clock is enabled at reset, and can be disabled in the power manager. it is recommended to disable the mci before disabling the clock, to avoid freezing the mci in an undefined state. 30.5.4 interrupt the mci interrupt request line is connected to the interrupt controller. using the mci interrupt requires the interrupt controller to be programmed first. 30.6 functional description 30.6.1 bus topology figure 30-3. multimedia memory card bus topology table 30-1. i/o lines description pin name pin description type (1) 1. pp: push/pull, od: open drain comments cmd[1:0] command/response input/output/ pp/od cmd of a mmc or sdcard/sdio clk clock input/output clk of a mmc or sd card/sdio data[7:0] data 0..7 of slot a input/output/pp dat[0..7] of a mmc dat[0..3] of a sd card / sdio data[15:8] data 0..7 of slot b input/output/pp dat[0..7] of a mmc dat[0..3] of a sd card / sdio 1 2 3 4 5 6 mmc 7 9 10 1213 8
836 32072d?04/2011 at32uc3a3/a4 the multimedia card communication is based on a 13-pin serial bus interface. it has three com- munication lines and four supply lines. notes: 1. i: input, o: output, pp: push/pull, od: open drain. figure 30-4. mmc bus connections (one slot) figure 30-5. sd memory card bus topology table 30-2. bus topology pin number name type (1) description mci pin name (2) (slot z) 1 dat[3] i/o/pp data dataz[3] 2 cmd i/o/pp/od command/response cmdz 3 vss1 s supply voltage ground vss 4 vdd s supply voltage vdd 5 clk i/o clock clk 6 vss2 s supply voltage ground vss 7 dat[0] i/o/pp data 0 dataz[0] 8 dat[1] i/o/pp data 1 dataz[1] 9 dat[2] i/o/pp data 2 dataz[2] 10 dat[4] i/o/pp data 4 dataz[4] 11 dat[5] i/o/pp data 5 dataz[5] 12 dat[6] i/o/pp data 6 dataz[6] 13 dat[7] i/o/pp data 7 dataz[7] clk data[0] cmd mci 1 2 3 4 5 6 mmc2 7 910 12 13 8 11 1 2 3 4 5 6 mmc3 7 910 12 13 8 11 1 2 3 4 5 6 mmc1 7 910 12 13 8 11 12 4 3 5678 9 sdcard
837 32072d?04/2011 at32uc3a3/a4 the sd memory card bus includes the signals listed in table 30-3 on page 837 . notes: 1. i: input, o: output, pp: push pull, od: open drain. figure 30-6. sd card bus connections with one slot figure 30-7. sd card bus connections with two slots table 30-3. sd memory card bus signals pin number name type (1) description mci pin name (2) (slot z) 1 cd/dat[3] i/o/pp card detect/ data line bit 3 dataz[3] 2 cmd pp command/response cmdz 3 vss1 s supply voltage ground vss 4 vdd s supply voltage vdd 5 clk i/o clock clk 6 vss2 s supply voltage ground vss 7 dat[0] i/o/pp data line bit 0 dataz[0] 8 dat[1] i/o/pp data line bit 1 or interrupt dataz[1] 9 dat[2] i/o/pp data line bit 2 dataz[2] 2 9 345678 sdcard 1 cmd clk data[3:0] 5 23 6 1478 9 sdcard1 5 23 6 1478 9 sdcard2 data[7:4] cmd[0] clk data[3:0] cmd[1]
838 32072d?04/2011 at32uc3a3/a4 figure 30-8. mixing multimedia and sd memory cards with two slots when the mci is configured to operate with sd memory cards, the width of the data bus can be selected in the sdcard /sdio bus width fi eld in the sdcr register (sdcr.sdcbus). see sec- tion ?30.7.4? on page 859. for details. in the case of multimedia cards, only the data line 0 is used. the other data lines can be used as independent gpios. 30.6.2 multimedia card operations after a power-on reset, the cards are initialized by a special message-based multimedia card bus protocol. each message is represented by one of the following tokens: ? command: a command is a token that starts an operation. a command is sent from the host either to a single card (addressed command) or to all connected cards (broadcast command). a command is transferred serially on the cmd line. ? response: a response is a token which is sent from an addressed card or (synchronously) from all connected cards to the host as an answer to a previously received command. a response is transferred serially on the cmd line. ? data: data can be transferred from the card to the host or vice versa. data is transferred via the data line. card addressing is implemented using a sess ion address assigned during the initialization phase by the bus controller to all currently connected cards. their unique cid number identifies individual cards. the structure of commands, resp onses and data blocks is descr ibed in the multimedia-card system specification. refer also to table 30-5 on page 840 . multimediacard bus data transfers are composed of these tokens. 4 9 23 156 7 8 sdcard data[7:0] cmd[0] clk data[11:8] cmd[1] 1 2 3 4 5 6 mmc1 7 910 12 13 8 11 1 2 3 4 5 6 mmc2 7 910 12 13 8 11 1 2 3 4 5 6 mmc3 7 910 12 13 8 11
839 32072d?04/2011 at32uc3a3/a4 there are different types of operations. addressed operations always contain a command and a response token. in addition, some operations have a data token; the others transfer their infor- mation directly within the command or response structure. in this case, no data token is present in an operation. the bits on the dat and the cmd lines are transferred synchronous to the mci clock (clk). two types of data transfer commands are defined: ? sequential commands: these commands initiate a continuous data stream. they are terminated only when a stop command follows on the cmd line. this mode reduces the command overhead to an absolute minimum. ? block-oriented commands: these commands send a data block succeeded by crc bits. both read and write operations allow either single or multiple block transmission. a multiple block transmission is terminated when a stop co mmand follows on the cm d line similarly to the sequential read or when a multiple block transmission has a pre-defined block count ( see sec- tion ?30.6.3? on page 841. ). the mci provides a set of registers to perform the entire range of multimedia card operations. 30.6.2.1 command - response operation after reset, the mci is disabled and becomes valid after setting the multi-media interface enable bit in the control register (cr.mcien). the power save mode enable bit in the cr regi ster (cr.pwen) saves power by dividing the mci clock (clk) by 2 pwsdiv + 1 when the bus is inactive. the power saving divider field locates in the mode register (mr.pwsdiv). the two bits, read proof enable and write proof enable in the mr register (mr.rdproof and mr.wrproof) allow stopping the mci clock (clk) during read or write access if the internal fifo is full. this will guarantee data inte grity, not bandwidth. all the timings for multimedia card are defined in the multim ediacard system specification. the two bus modes (open drain and push/pull) needed to process all the operations are defined in the command register (cmdr). the cmdr register allows a command to be carried out. for example, to perform an all_send_cid command table 30-4. all_send_cid command host command n id cycles cid cmd s t content crc e z ****** z s t content z z z
840 32072d?04/2011 at32uc3a3/a4 the command all_send_cid and the fields and values for cmdr register are described in table 30-5 on page 840 and table 30-6 on page 840 . note: bcr means broadcast command with response. the argument register (argr) contains the argument field of the command. to send a command, the user must perform the following steps: ? set the argr register with the command argument. ? set the cmdr register (see table 30-6 on page 840 ). the command is sent immediately after writing the command register. as soon as the command register is written, then the command ready bit in the status register (sr.cmdrdy) is cleared. it is released and the end of the card response. if the command requires a response, it can be read in the response registers (rsprn). the response size can be from 48 bits up to 136 bits depending on the command. the mci embeds an error detection to prevent any corrupted data during the transfer. the following flowchart shows how to send a command to the card and read the response if needed. in this example, the status register bits are polled but setting the appropriate bits in the interrupt enable register (ier) allows using an interrupt method. table 30-5. all_send_cid command description cmd index type argument resp abbreviation command description cmd2 bcr [31:0] stuff bits r2 all_send_cid asks all cards to send their cid numbers on the cmd line table 30-6. fields and values for the cmdr register field value cmdnb (command number) 2 (cmd2) rsptyp (response type) 2 (r2: 136 bits response) spcmd (special command) 0 (not a special command) opcmd (open drain command) 1 maxlat (max latency for command to response) 0 (nid cycles ==> 5 cycles) trcmd (transfer command) 0 (no transfer) trdir (transfer direction) x (available only in transfer command) trtyp (transfer type) x (available only in transfer command) iospcmd (sdio special command) 0 (not a special command)
841 32072d?04/2011 at32uc3a3/a4 figure 30-9. command/response functional flow diagram note: 1. if the command is send_op_cond, the c rc error bit is always present (refer to r3 response in the multimedi a card specification). 30.6.3 data transfer operation the multimedia card allo ws several read/write operations (single block, multiple blocks, stream, etc.). these kind of transfers can be selected setting the transfer type field in the cmdr regis- ter (cmdr.trtyp). these operations can be done using the features of the dma controller. in all cases, the data block length must be defi ned either in the data block length field in the mr register (mr.blklen)), or in the block regi ster (blkr). this field determines the size of the data block. set the command argument argr = argument (1) set the command cmd = command read the sr register 0 yes 1 sr.cmdrdy wait for sr.cmdry bit set to one check error bits in the sr register (1) status error bits? return ok return error (1) read response if required
842 32072d?04/2011 at32uc3a3/a4 consequent to mmc specification 3.1, two types of multiple block read (or write) transactions are defined (the host can use either one at any time): ? open-ended/infinite multiple block read (or write): the number of blocks for the read (or write) multiple block operation is not defined. the card will continuously transfer (o r program) data blocks until a stop transmission command is received. ? multiple block read (or write) with pre-defined block count (since version 3.1 and higher): the card will transfer (or program ) the requested number of data blocks and terminat e the trans- action. the stop command is not required at the end of this type of multiple block read (or write), unless terminated with an error. in order to start a multiple block read (o r write) with pre-defined block count, the host mu st correctly set the blkr register. otherwise the card will start an open- ended multiple block read. the mmc/sdio block count - sdio byte count field in the blkr register (blkr.bcnt) defines the number of blocks to transfer (from 1 to 65535 blocks). writing zero to this field corresponds to an infinite block transfer. 30.6.4 read/write operation the following flowchart shows how to read a single block with or without use of dma controller facilities. in this example (see figure 30-10 on page 843 ), a polling method is used to wait for the end of read. similarly, the user can configure the ier register to trigger an interrupt at the end of read.
843 32072d?04/2011 at32uc3a3/a4 figure 30-10. read functional flow diagram note: 1. it is assumed that this command has been correctly sent (see figure 30-9 on page 841 ). 2. this field is also accessible in the blkr register. write a one in the dma.dmaen bit write the blocklenght in the mr.blklen field (2) send select/deselect_card command (1) to select the card send set_blocklen command (1) no yes read with dma write a zero in the dma.dmaen bit write the blocklenght in the mr.blklen field (2) write the block count in the blkr.bcnt field (if necessary) read data in the rdr register number of words to read = number of words to read -1 send read_single_block command (1) configure the dma channel x write the data adress in the dma controller write the (mr.blklen)/4 for transfer size in the dma controller number of words to read = (mr.blklen)/4 number of words to read = 0 ? yes no yes yes read the sr register sr.xfrdone = 0 ? no return read the sr register sr.rxrdy = 0 ? no return send read_single_block command (1)
844 32072d?04/2011 at32uc3a3/a4 in write operation, the padding value bit in the mr register (mr.padv) is used to define the padding value when writing non-multiple block si ze. when the mr.padv is zero, then 0x00 value is used when padding data, otherwise 0xff is used. write a one in the dma hardware handshaking enable bit in the dma configuration register (dma.dmaen) enables dma transfer. the following flowchart shows how to write a sing le block with or without use of dma facilities (see figure 30-11 on page 845 ). polling or interrupt method can be used to wait for the end of write according to the contents of the interrupt mask register (imr).
845 32072d?04/2011 at32uc3a3/a4 figure 30-11. write functional flow diagram note: 1. it is assumed that this command has been correctly sent (see figure 30-9 on page 841 ). 2. this field is also accessible in blkr register. write using dma no yes yes write a zero in the dma.dmaen bit write the blocklenght in the mr.blklen field (2) write the block count in the blkr.bcnt field (if necessary) number of words to write = blocklength/4 number of words to write = 0 ? no no yes read the sr register sr.txrdy = 0 ? write data to transmit in the tdr register number of words to write = number of words to write - 1 return return yes no read the sr register sr.notbusy = 0 ? enable the dma channel x write a one in the dma.dmaen bit write the blocklenght in the mr.blklen field (2) send select/deselect_card command (1) to select the card send set_blocklen command (1) send write_single_block command (1) send write_single_block command (1) configure the dma channel x write the data adress in the dma controller write the (mr.blklen)/4 for transfer size in the dma controller
846 32072d?04/2011 at32uc3a3/a4 the following flowchart shows how to manage a multiple write block transfer with the dma con- troller (see figure 30-12 on page 847 ). polling or interrupt method can be used to wait for the end of write according to the contents of the imr register.
847 32072d?04/2011 at32uc3a3/a4 figure 30-12. multiple write functi onal flow diagram note: 1. it is assumed that this command has been correctly sent (see figure 30-9 on page 841 ). 2. this field is also accessible in blkr register. send select/deselect_card command (1) to select the card send set_blocklen command (1) no read the sr register sr.blke = 0 ? enable the dma channel x write a zero in the dma.dmaen bit write the block lenght in the mr.blklen field (2) write the block count in the blkr.bcnt field (if necessary) send write_multiple_block command (1) configure the dma channel x write the data adress in the dma controller write the (mr.blklen)/4 for transfer size in the dma controller yes send stop_transmission command (1) sr.notbusy = 0 ? yes no return
848 32072d?04/2011 at32uc3a3/a4 30.6.4.1 write_single_block operation using dma controller 1. wait until the current command execution has successfully terminated. c. check that the transfer done bit in the sr register (sr.xfrdone) is set 2. write the block length in the card. this value defines the value block_lenght. 3. write the mr.blklen with block_lenght value. 4. configure the dma channe l in the dma controller. 5. write the dma register with the following fields: ? write the dma_offset to the dma write buffer offset field (dma.offset) . ? write the dma channel read and write chunk size field (dma.chksize). ? write a one to he dma.dmaen bit to enable dma hardware handshaking in the mci. 6. write a one to the dma transfer done bit in ier register (ier.dmadone). 7. issue a write_single_block command. 8. wait for dma transfer done bit in sr register (sr.dmadone) is set. 30.6.4.2 read_single_block operation using dma controller 1. wait until the current command execution has successfully terminated. d. check that the sr.xfrdone bit is set. 2. write the block length in the card. this value defines the value block_lenght. 3. write the mr.blklen with block_lenght value. 4. configure the dma channe l in the dma controller. 5. write the dma register with the following fields: ? write zero to the dma.offset field . ? write the dma.chksize field. ? write to one the dma.dmaen bit to enable dma hardware handshaking in the mci. 6. write a one to the ier.dmadone bit. 7. issue a read_single_block command. 8. wait for sr.dmadone bit is set. 30.6.4.3 write_multiple_block 1. wait until the current command execution has successfully terminated. a. check that the sr.xfrdone bit is set. 2. write the block length in the card. this value defines the value block_lenght. 3. write the mr.blklen with block_lenght value. 4. program the dma controller to use a list of descriptors. each descriptor transfers one block of data. 5. program the dma register with the following fields: ? write the dma_offset in the dma.offset field . ? write the dma.chksize field. ? write a one to the dma.dmaen bit to enable dma hardware handshaking in the mci. 6. write a one to the ier.dmadone bit. 7. issue a write_multiple_block command. 8. wait for dma chained buffer transfer complete interrupt.
849 32072d?04/2011 at32uc3a3/a4 30.6.4.4 read_multiple_block 1. wait until the current command execution has successfully terminated. a. check that the sr.cmdrdy and the sr.notbusy are set. 2. write the block length in the card. this value defines the value block_lenght. 3. write the mr.blklen with block_lenght value. 4. program the dma controller to use a list of descriptors. 5. write the dma register with the following fields: ? write zero to the dma.offset . ? write the dma.chksize. ? write a one to the dma.dmaen bit to enable dma hardware handshaking in the mci. 6. write a one to the ier.dmadone bit. 7. issue a read_multiple_block command. 8. wait for dma end of chained buffer transfer interrupt. 30.6.5 sd/sdio card operation the mci allows processing of sd memory (secure digital memory card) and sdio (sd input output) card commands. sd/sdio cards are based on the multimedia card (mmc) format, but are physically slightly thicker and feature higher data transfer rates, a lock switch on the side to prevent accidental overwriting and security featur es. the physical form factor, pin assignment and data transfer protocol are forward-compatible with the multimedia card with some additions. sd slots can actually be used for more than flash memory ca rds. devices that support sdio can use small devices designed for the sd form factor, such as gps receivers, wi-fi or bluetooth adapters, modems, barcode readers, irda adapters, fm radio tuners, rfid readers, digital cameras and more. sd/sdio is covered by numerous patents and trademarks, and licensing is only available through the secure digital card association. the sd/sdio card communicat ion is based on a nine-pin interface (clock, command, four data and three power lines). the communicatio n protocol is defined as a part of this speci- fication. the main difference between the sd/sdio card and the multimedia card is the initialization process. the sd/sdio card register (sdcr) allows sele ction of the card slot (sdcsel) and the data bus width (sdcbus). the sd/sdio card bus allows dynamic configur ation of the number of data lines. after power up, by default, the sd/sdio card uses only dat[0] for data transfer. after initialization, the host can change the bus width (number of active data lines). 30.6.5.1 sdio data transfer type sdio cards may transfer data in either a multi-byte (1 to 512 bytes) or an optional block format (1 to 511 blocks), while the sd memory cards are fixed in the block transfer mode. the cmdr.trtyp field allows to choose between sdio byte or sdio block transfer. the number of bytes/blocks to transfer is set through the bcnt field in the blkr register. in sdio block mode, the field blklen must be set to the data block size while this field is not used in sdio byte mode.
850 32072d?04/2011 at32uc3a3/a4 an sdio card can have multiple i/o or combined i/o and memo ry (called combo card). within a multi-function sdio or a combo card, there are multiple devices (i/o and memory) that share access to the sd bus. in order to allow the sharing of access to the host among multiple devices, sdio and combo cards can implement the optional concept of suspend/resume (refer to the sdio specification for more details). to send a suspend or a resume command, the host must set the sdio special command fiel d in cmdr register (cmdr.iospcmd). 30.6.5.2 sdio interrupts each function within an sdio or combo card may implement interrupts (refer to the sdio specification for more details). in order to allow the sdio card to interrupt the host, an interrupt function is added to a pin on the dat[1] line to signal the card?s interrupt to the host. an sdio interrupt on each slot can be enabled in the ier register. the sdio interrupt is sampled regard- less of the currently selected slot. 30.6.6 ce-ata operation ce-ata maps the streamlined ata command set onto the mmc interface. the ata task file is mapped onto mmc register space. ce-ata utilizes five mmc commands: ? go_idle_state (cmd0): used for hard reset. ? stop_transmission (cmd12): causes the ata command currently executing to be aborted. ? fast_io (cmd39): used for singl e register access to the ata taskfile registers, eight bit access only. ? rw_multiple_registers (cmd60): used to issue an ata command or to access the control/status registers. ? rw_multiple_block (cmd61): used to transfer data for an ata command. ce-ata utilizes the same mmc command s equences for initialization as traditional mmc devices. 30.6.6.1 executing an ata polling command 1. issue read_dma_ext with rw_multiple_register (cmd60) for eight kb of data. 2. read the ata status register until drq is set. 3. issue rw_multiple_block (cmd61) to transfer data. 4. read the ata status register until drq && bsy are set to 0. 30.6.6.2 executing an ata interrupt command 1. issue read_dma_ext with rw_multiple_register (cmd60) for eight kb of data with the ien field written to zero to enable the command completion signal in the device. 2. issue rw_multiple_block (cmd61) to transfer data. 3. wait for completion signal received interrupt. 30.6.6.3 aborting an ata command if the host needs to abort an ata command prior to the completion signal it must send a special command to avoid potential collision on the command line. the special command field of
851 32072d?04/2011 at32uc3a3/a4 cmdr register (cmdr.spcmd) must be set to three to issue the ce-ata completion signal disable command. 30.6.6.4 ce-ata error recovery several methods of ata command failure may occur, including: ? no response to an mmc command, such as rw_multiple_register (cmd60). ? crc is invalid for an mmc command or response. ? crc16 is invalid for an mmc data packet. ? ata status register reflects an error by setting the err bit to one. ? the command completion signal does not arrive within a host specified time out period. error conditions are expected to happen infreq uently. thus, a robust error recovery mechanism may be used for each error event. the recommended error recovery procedure after a time-out is: ? issue the command completion signal disable if ien was cleared to zero and the rw_multiple_block (cmd61) response has been received. ? issue stop_transmission (cmd12) and successfully receive the r1 response. ? issue a software reset to the ce-ata device using fast_io (cmd39). if stop_tranmission (cmd12) is successful , then the device is again ready for ata com- mands. however, if the error recovery procedure does not work as expected or there is another time-out, the next step is to issue go_idle_state (cmd0) to the device. go_idle_state (cmd0) is a hard reset to the device and completely resets all device states. note that after issuing go_idle_state (cmd0), a ll device initialization needs to be completed again. if the ce-ata device completes all mmc commands corr ectly but fails the ata command with the err bit set in the ata status register , no error recovery action is required. the ata command itself failed implying that the device could not complete the action requested, how- ever, there was no communication or protocol failu re. after the device signals an error by setting the err bit to one in the ata status register, the host may attempt to retry the command. 30.6.7 mci boot operation mode in boot operation mode, the processor can read boot data from the slave (mmc device) by keep- ing the cmd line low after power-on before is suing cmd1. the data can be read from either boot area or user area depending on register setting. 30.6.7.1 boot procedure, processor mode 1. configure mci2 data bus width programming sdcbus field in the mci_sdcr regis- ter. the boot_bus_width field located in the device extended csd register must be set accordingly. 2. set the bytecount to 512 bytes and the blockcount to the desired number of block, writ- ing blklen and bcnt fields of the mci_blkr register. 3. issue the boot operation request command by writing to the mc i_cmdr register with spcmd field set to bootreq, trdir set to read and trcmd set to ?start data transfer?. 4. the boot_ack field located in the mci_cmdr register must be set to one, if the boot_ack field of the mmc device located in the extended csd register is set to one. 5. host processor can copy boot data sequentialy as soon as the rxrdy flag is asserted.
852 32072d?04/2011 at32uc3a3/a4 6. when data transfer is completed, host processor shall terminate the boot stream by writing the mci_cmdr register with spcmd field set to bootend. 30.6.7.2 boot procedure, dma mode 1. configure mci2 data bus width programming sdcbus field in the mci_sdcr regis- ter. the boot_bus_width field in the device extended csd register must be set accordingly. 2. set the bytecount to 512 bytes and the blockcount to the desired number of block, writ- ing blklen and bcnt fields of the mci_blkr register. 3. enable dma transfer in the mci_dma register. 4. configure dma controller, program the total amount of data to be transferred and enable the relevant channel. 5. issue the boot operation request command by writing to the mc i_cmdr register with spcnd set to bootreq, trdir set to read and trcmd set to ?start data transfer?. 6. dma controller copies the boot partition to the memory. 7. when dma transfer is completed, host processor shall terminate the boot stream by writing the mci_cmdr register with spcmd field set to bootend. 30.6.8 mci transfer done timings 30.6.8.1 definition the sr.xfrdone bit indicates exactly when the read or write sequence is finished. 30.6.8.2 read access during a read access, the sr.xfrdone bit behaves as shown in figure 30-13 on page 852 . figure 30-13. sr.xfrdone during a read access cmd line mci read cmd card response cmdrdy flag data 1st block last block not busy flag xfrdone flag the cmdrdy flag is released 8 t bit lafter the end of the card response.
853 32072d?04/2011 at32uc3a3/a4 30.6.8.3 write access during a write access, the sr.xfrdone bit behaves as shown in figure 30-14 on page 853 . figure 30-14. sr.xfrdone during a write access 30.7 user interface table 30-7. mci register memory map offset register name access reset 0x000 control register cr write-only 0x00000000 0x004 mode register mr read-write 0x00000000 0x008 data time-out register dtor read-write 0x00000000 0x00c sd/sdio card register sdcr read-write 0x00000000 0x010 argument register argr read-write 0x00000000 0x014 command register cmdr write-only 0x00000000 0x018 block register blkr read-write 0x00000000 0x01c completion signal time-out register cstor read-write 0x00000000 0x020 response register rspr read-only 0x00000000 0x024 response register rspr1 read-only 0x00000000 0x028 response register rspr2 read-only 0x00000000 0x02c response register rspr3 read-only 0x00000000 0x030 receive data register rdr read-only 0x00000000 0x034 transmit data register tdr write-only 0x00000000 0x040 status register sr read-only 0x0c000025 cmd line mci writecmd card response cmdrdy flag data bus - d0 1st block not busy flag xfrdone flag the cmdrdy flag is released 8 t bit lafter the end of the card response. last block d0 1st block last block d0 is tied by the card d0 is released
854 32072d?04/2011 at32uc3a3/a4 0x044 interrupt enable register ier write-only 0x00000000 0x048 interrupt disable register idr write-only 0x00000000 0x04c interrupt mask register imr read-only 0x00000000 0x050 dma configuration register dma read-write 0x00000000 0x054 configuration register cfg read-write 0x00000000 0x0e4 write protection mode register wpmr read-write 0x00000000 0x0e8 write protection status register wpsr read-only 0x00000000 0x0fc version register version read-only - (1) 0x200-0x3ffc fifo memory aperture ? read-write 0x00000000 1. the reset value are device specific. please refer to t he module configuration secti on at the end of this chapter. table 30-7. mci register memory map offset register name access reset
855 32072d?04/2011 at32uc3a3/a4 30.7.1 control register name: cr access type: write-only offset: 0x000 reset value: 0x00000000 ? swrst: software reset writing a one to this bit will reset the mci interface. writing a zero to this bit has no effect. ? iowaitdis: sdio read wait disable writing a one to this bit will disable the sdio read wait operation. writing a zero to this bit has no effect. ? iowaiten: sdio read wait enable writing a one to this bit will enable the sdio read wait operation. writing a zero to this bit has no effect. ? pwsdis: power save mode disable writing a one to this bit will disable the power saving mode. writing a zero to this bit has no effect. ? pwsen: power save mode enable writing a one to this bit and a zero to pwsdis will enable the power saving mode. writing a one to this bit and a one to pwsdis will disable the power saving mode. writing a zero to this bit has no effect. warning: before enabling this mode, the user must write a value different from 0 to the pwsdiv field. ? mcidis: multi-medi a interface disable writing a one to this bit will di sable the multi-media interface. writing a zero to this bit has no effect. ? mcien: multi-media interface enable writing a one to this bit and a zero to mcidis will enable the multi-media interface. writing a one to this bit and a one to mcidis will disable the multi-media interface. writing a zero to this bit has no effect. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 swrst - iowaitdis iowaiten pwsdis pwsen mcidis mcien
856 32072d?04/2011 at32uc3a3/a4 30.7.2 mode register name: mr access type: read-write offset: 0x004 reset value: 0x00000000 ? blklen[15:0]: da ta block length this field determines the size of the data block. this field is also accessible in the blkr register. if fbyte bit is zero, the blken[1 :0] field must be written to 0b00 notes: 1. in sdio byte mode, blklen field is not used. 2. blklen should be written to one before sending the data transfer command. otherwise, overrun may occur even if rdproof bit is one. ? padv: padding value 0: 0x00 value is used when padding data in write transfer. 1: 0xff value is used when padding data in write transfer. padv is used only in manual transfer. ? fbyte: force byte transfer enabling force byte transfer allows byte transfers, so that tr ansfer of blocks with a size different from modulo 4 can be supported. warning: blklen value depends on fbyte. writing a one to this bit will enable the force byte transfer. writing a zero to this bit will disable the force byte transfer. ? wrproof write proof enable enabling write proof allows to stop the mci clock (clk) during wr ite access if the internal fifo is full. this will guarantee d ata integrity, not bandwidth. writing a one to this bit will enable the write proof mode. writing a zero to this bit will disable the write proof mode. ? rdproof read proof enable enabling read proof allows to stop the mci clock (clk) during r ead access if the internal fifo is full. this will guarantee dat a integrity, not bandwidth. writing a one to this bit will enable the read proof mode. writing a zero to this bit will disable the read proof mode. 31 30 29 28 27 26 25 24 blklen[15:8] 23 22 21 20 19 18 17 16 blklen[7:0] 15 14 13 12 11 10 9 8 - padv fbyte wrproof rdproof pwsdiv 76543210 clkdiv
857 32072d?04/2011 at32uc3a3/a4 ? pwsdiv: power saving divider multimedia card interface clock is divided by 2 (pwsdiv) + 1 when entering power saving mode. warning: this value must be different from zero before enab ling the power save mode in the cr register (cr.pwsen). ? clkdiv: clock divider the multimedia card interface clock (clk) is clk_mci divided by (2*(clkdiv+1)).
858 32072d?04/2011 at32uc3a3/a4 30.7.3 data time-out register name: dtor access type: read/write offset: 0x008 reset value: 0x00000000 these two fields determine th e maximum number of clk_mci cycles that the mci waits between two data block transfers. it is equal to (dtocyc x multiplier). if the data time-out defined by dtocyc and dtomul has been exceeded, the data time-out er ror bit in the sr register (sr.dtoe) is set. ? dtomul: data time-out multiplier multiplier is defined by dtomul as shown in the following table ? dtocyc: data time-out cycle number 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 -dtomul dtocyc dtomul multiplier 01 116 2128 3256 4 1024 5 4096 6 65536 7 1048576
859 32072d?04/2011 at32uc3a3/a4 30.7.4 sdcard/sdio register name: sdcr access type: read/write offset: 0x00c reset value: 0x00000000 ? sdcbus: sdcard/sdio bus width ? sdcsel: sdcard/sdio slot 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 sdcbus ? ? ? ? sdcsel sdcbus bus width 01 bit 1reserved 2 4 bits 3 8 bits sdcsel sdcard/sdio slot 0 slot a is selected. 1 slot b is selected. 2 reserved. 3 reserved.
860 32072d?04/2011 at32uc3a3/a4 30.7.5 argument register name: argr access type: read/write offset: 0x010 reset value: 0x00000000 ? arg[31:0]: command argument this field contains the argument field of the command. 31 30 29 28 27 26 25 24 arg[31:24] 23 22 21 20 19 18 17 16 arg[23:16] 15 14 13 12 11 10 9 8 arg[15:8] 76543210 arg[7:0]
861 32072d?04/2011 at32uc3a3/a4 30.7.6 command register name: cmdr access type: write-only offset: 0x014 reset value: 0x00000000 this register is write-pr otected while sr.cmdrdy is zero. if an interrupt comm and is sent, this register is only writable by an interrupt response (spcmd field). this means that the cu rrent command execution cannot be interrupted or modified. ? boot_ack: boot operation acknowledge the master can choose to receive t he boot acknowledge from t he slave when a boot request command is isssued. writing a one to this bit indicates that a boot acknolwedge is expected within a programmable amount of time defined with dtomul and dtocyc fields located in the dtor register. if the acknowledge pattern is not received then an acknowledge timeout error is raised. if the acknowledge pattern is corrupted then an acknowledge pattern error is set. ? atacs: ata with command completion signal writing a one to this bit will configure ata completion signal withi n a programmed amount of time in completion signal time-out register (cstor). writing a zero to this bit will configure no ata completion signal. ? iospcmd: sdio special command 31 30 29 28 27 26 25 24 - - - - bootack atacs iospcmd 23 22 21 20 19 18 17 16 - - trtyp trdir trcmd 15 14 13 12 11 10 9 8 - - - maxlat opdcmd spcmd 76543210 rsptyp cmdnb iospcmd sdio special command type 0 not a sdio special command 1 sdio suspend command 2 sdio resume command 3reserved
862 32072d?04/2011 at32uc3a3/a4 ? trtyp: transfer type ? trdir: transfer direction writing a zero to this bit will configure the transfer direction as write transfer. writing a one to this bit will configure the transfer direction as read transfer. ? trcmd: transfer command ? maxlat: max latency for command to response writing a zero to this bit will configure a 5-cycle max latency. writing a one to this bit will configure a 64-cycle max latency. ? opdcmd: open drain command writing a zero to this bit will configure the push-pull command. writing a one to this bit will configure the open-drain command. ? spcmd: special command trtyp transfer type 0 mmc/sdcard single block 1 mmc/sdcard multiple block 2 mmc stream 3 reserved 4 sdio byte 5sdio block others reserved trcmd transfer type 0 no data transfer 1 start data transfer 2 stop data transfer 3 reserved spcmd command 0 not a special cmd. 1 initialization cmd: 74 clock cycles for initialization sequence. 2 synchronized cmd: wait for the end of the current data block transfer before sending the pending command. 3 ce-ata completion signal disable command. the host cancels the ability for the device to return a command completion signal on the command line. 4 interrupt command: corresponds to the interrupt mode (cmd40). 5 interrupt response: corresponds to the interrupt mode (cmd40). others reserved
863 32072d?04/2011 at32uc3a3/a4 ? rsptyp: response type ? cmdnb: command number the command number to transmit. rsp response type 0 no response. 1 48-bit response. 2 136-bit response. 3 r1b response type
864 32072d?04/2011 at32uc3a3/a4 30.7.7 block register name: blkr access type: read/write offset: 0x018 reset value: 0x00000000 ? blklen: data block length this field determines the size of the data block. this field is also accessible in the mr register. if mr.fbyte bit is zero, the blken[ 17:16] field must be written to 0b00 notes: 1. in sdio byte mode, blklen field is not used. 2. blklen should be specified before sending t he data transfer command. otherwise, overrun may occur (even if mr.rdproof bit is set). ? bcnt: mmc/sdio block count - sdio byte count this field determines the number of data byte(s) or block(s) to transfer. the transfer data type and the authorized values fo r bcnt field are determined by cmdr.trtyp field: warning: in sdio byte and block modes, writing to the seven last bi ts of bcnt field is forbidden and may lead to unpredictable results. 31 30 29 28 27 26 25 24 blklen[15:8] 23 22 21 20 19 18 17 16 blklen[7:0] 15 14 13 12 11 10 9 8 bcnt[15:8] 76543210 bcnt[7:0] trtyp type of transfer bcnt authorized values 0 mmc/sdcard multiple block from 1 to 65535: value 0 corresponds to an infinite block transfer. 2 sdio byte from 1 to 512 bytes: value 0 corresponds to a 512-byte transfer. values from 0x200 to 0xffff are forbidden. 3sdio block from 1 to 511 blocks: value 0 corresponds to an infinite block transfer. values from 0x200 to 0xffff are forbidden. others - reserved.
865 32072d?04/2011 at32uc3a3/a4 30.7.8 completion signal time-out register name: cstor access type: read-write offset: 0x01c reset value: 0x00000000 these two fields determines the maximum number of clk_mci cycles that the mci wa its between two data block transfers. its value is calculated by (cstocyc x multiplier). these two fields also determine the maximum number of clk_ mci cycles that the mci wait s between the end of the data transfer and the assertion of the completion signal. the data transfer comprises data phase and the optional busy phase. if a non-data ata command is issued, the mci starts waiting imme diately after the end of the re sponse until the completion signal. if the data time-out defined by cstocyc and cstomul has been exceeded, the completion signal time-out error bit in the sr register (sr.cstoe) is set. ? cstomul: completion signal time-out multiplier multiplier is defined by cstomul as shown in the following table: ? cstocyc: completion signal time-out cycle number 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - cstomul cstocyc cstomul multiplier 01 116 2128 3256 4 1024 5 4096 6 65536 7 1048576
866 32072d?04/2011 at32uc3a3/a4 30.7.9 response register n name: rsprn access type: read-only offset: 0x020 + 0*0x04 reset value: 0x00000000 ? rsp[31:0]: response the response register can be read by n access(es) at the same rsprn or at consecutive addresses (0x20 + n*0x04). n depends on the size of the response. 31 30 29 28 27 26 25 24 rsp[31:24] 23 22 21 20 19 18 17 16 rsp[23:16] 15 14 13 12 11 10 9 8 rsp[15:8] 76543210 rsp[7:0]
867 32072d?04/2011 at32uc3a3/a4 30.7.10 receive data register name: rdr access type: read-only offset: 0x030 reset value: 0x00000000 ? data[31:0]: data to read the last data received. 31 30 29 28 27 26 25 24 data[31:24] 23 22 21 20 19 18 17 16 data[23:16] 15 14 13 12 11 10 9 8 data[15:8] 76543210 data[7:0]
868 32072d?04/2011 at32uc3a3/a4 30.7.11 transmit data register name: tdr access type: write-only offset: 0x034 reset value: 0x00000000 ? data[31:0]: data to write the data to send. 31 30 29 28 27 26 25 24 data[31:24] 23 22 21 20 19 18 17 16 data[23:16] 15 14 13 12 11 10 9 8 data[15:8] 76543210 data[7:0]
869 32072d?04/2011 at32uc3a3/a4 30.7.12 status register name: sr access type: read-only offset: 0x040 reset value: 0x0c000025 ? ackrcve: boot operation acknowledge error this bit is set when a corrupted boot acknowlegde signal has been received. this bit is cleared by reading the sr register. ? ackrcv: boot operation acknowledge received this bit is set when a boot acknowledge signal has been received. this bit is cleared by reading the sr register. ? unre: underrun error this bit is set when at least one eight-bit data has been sent without valid information (not written). this bit is cleared when sending a new data transfer command if the flow error bit reset control mode in configuration register (cfg.ferrctrl) is zero or when reading the sr register if cfg.ferrctrl is one. ? ovre: overrun error this bit is set when at least one 8-bit received data has been lost (not read). this bit is cleared when sending a new data transfer command if cfg.ferrctrl is zero, or when reading the sr register if cfg.ferrctrl is one. ? xfrdone: transfer done this bit is set when the cr register is ready to operate and the data bus is in the idle state. this bit is cleared when a transfer is in progress. ? fifoempty: fifo empty this bit is set when the fifo is empty. this bit is cleared when the fi fo contains at least one byte. ? dmadone: dma transfer done this bit is set when the dm a buffer transfer is completed. this bit is cleared when reading the sr register. ? blkovre: dma block overrun error this bit is set when a new block of data is received and the dma controller has not started to move the current pending block. this bit is cleared when reading the sr register. 31 30 29 28 27 26 25 24 unre ovre ackrcve ackrcv xfrdone fifoempty dmadone blkovre 23 22 21 20 19 18 17 16 cstoe dtoe dcrce rtoe rende rcrce rdire rinde 15 14 13 12 11 10 9 8 txbufe rxbuff csrcv sdiowait - - sdioirqb sdioirqa 76543210 endtx endrx notbusy dtip blke txrdy rxrdy cmdrdy
870 32072d?04/2011 at32uc3a3/a4 ? cstoe: completion si gnal time-out error this bit is set when the completion signal time-out defined by the cstor.cstocyc field and the cstor.cstomul field is reached. this bit is cleared when reading the sr register. ? dtoe: data time-out error this bit is set when the data time-out defined by the dtor.dtocyc field and the dtor.dtomul field is reached. this bit is cleared when reading the sr register. ? dcrce: data crc error this bit is set when a crc16 error is detected in the last data block. this bit is cleared when reading the sr register. ? rtoe: response time-out error this bit is set when the response time-out defined by the cmdr.maxlat bit is reached. this bit is cleared when writing the cmdr register. ? rende: response end bit error this bit is set when the end bit of the response is not detected. this bit is cleared when writing the cmdr register. ? rcrce: response crc error this bit is set when a crc7 error is detected in the response. this bit is cleared when writing the cmdr register. ? rdire: response direction error this bit is set when the direction bit from card to host in the response is not detected. this bit is cleared when writing the cmdr register. ? rinde: response index error this bit is set when a mismatch is detected between the command index sent and the response index received. this bit is cleared when writing the cmdr register. ? txbufe: tx buffer empty status this bit is set when the dma tx buffer is empty. this bit is cleared when the dma tx buffer is not empty. ? rxbuff: rx buffer full status this bit is set when the dma rx buffer is full. this bit is cleared when the dma rx buffer is not full. ? csrcv: ce-ata completion signal received this bit is set when the device issues a command completion signal on the command line. this bit is cleared when reading the sr register. ? sdiowait: sdio read wait operation status this bit is set when the data bus has entered io wait state. this bit is cleared when normal bus operation. ? sdioirqb: sdio interrupt for slot b this bit is cleared when reading the sr register. this bit is set when a sdio interrupt on slot b occurs. ? sdioirqa: sdio interrupt for slot a this bit is set when a sdio interrupt on slot a occurs. this bit is cleared when reading the sr register. ? endtx: end of rx buffer this bit is set when the dma controller transmission is finished. this bit is cleared when the dma controller transmission is not finished. ? endrx: end of rx buffer this bit is set when the dma controller reception is finished. this bit is cleared when the dma controller reception is not finished. ? notbusy: mci not busy this bit must be used only for write operations.
871 32072d?04/2011 at32uc3a3/a4 a block write operation uses a simple busy signalling of the wr ite operation duration on the data (dat[0]) line: during a data transfer block, if the card does not have a free data receive buffer, the card indicates this condition by pulling down the dat a line (dat[0]) to low. the card stops pulling down the data line as soon as at least one receive buffer for the defined data transfer block length becomes free. the notbusy bit allows to deal with these different states. 1: mci is ready for new data transfer. 0: mci is not ready for new data transfer. this bit is cleared at the end of the card response. this bit is set when the busy state on the data line is ended. this corresponds to a free internal data receive buffer of the c ard. refer to the mmc or sd specification fo r more details concerning the busy behavior. ? dtip: data transfer in progress this bit is set when the current data transfer is in progress. this bit is cleared at the end of the crc16 calculation 1: the current data transfer is still in progress. 0: no data transfer in progress. ? blke: data block ended this bit must be used only for write operations. this bit is set when a data block transfer has ended. this bit is cleared when reading sr. 1: a data block transfer has ended, including the crc16 status transmission, the bit is set fo r each transmitted crc status. 0: a data block transfer is not yet finished. refer to the mmc or sd specification fo r more details concerning the crc status. ? txrdy: transmit ready this bit is set when the last data writt en in the tdr register has been transferred. this bit is cleared the last data written in the tdr register has not yet been transferred. ? rxrdy: receiver ready this bit is set when the data has been rece ived since the last read of the rdr register. this bit is cleared when the data has not yet been received since the last read of the rdr register. ? cmdrdy: command ready this bit is set when the last command has been sent. this bit is cleared when writing the cmdr register
872 32072d?04/2011 at32uc3a3/a4 30.7.13 interrupt enable register name: ier access type: write-only offset: 0x044 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will set the corresponding bit in imr. 31 30 29 28 27 26 25 24 unre ovre ackrcve ackrcv xfrdone fifoempty dmadone blkovre 23 22 21 20 19 18 17 16 cstoe dtoe dcrce rtoe rende rcrce rdire rinde 15 14 13 12 11 10 9 8 txbuff rxbuff csrcv sdiowait - - sdioirqb sdioirqa 76543210 endtx endrx notbusy dtip blke txrdy rxrdy cmdrdy
873 32072d?04/2011 at32uc3a3/a4 30.7.14 interrupt disable register name: idr access type: write-only offset: 0x048 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in imr. 31 30 29 28 27 26 25 24 unre ovre ackrcve ackrcv xfrdone fifoempty dmadone blkovre 23 22 21 20 19 18 17 16 cstoe dtoe dcrce rtoe rende rcrce rdire rinde 15 14 13 12 11 10 9 8 txbuff rxbuff csrcv sdiowait - - sdioirqb sdioirqa 76543210 endtx endrx notbusy dtip blke txrdy rxrdy cmdrdy
874 32072d?04/2011 at32uc3a3/a4 30.7.15 interrupt mask register name: imr access type: read-only offset: 0x04c reset value: 0x00000000 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. a bit in this register is cleared when the corresponding bit in idr is written to one. a bit in this register is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 unre ovre ackrcve ackrcv xfrdone fifoempty dmadone blkovre 23 22 21 20 19 18 17 16 cstoe dtoe dcrce rtoe rende rcrce rdire rinde 15 14 13 12 11 10 9 8 txbuff rxbuff csrcv sdiowait - - sdioirqb sdioirqa 76543210 endtx endrx notbusy dtip blke txrdy rxrdy cmdrdy
875 32072d?04/2011 at32uc3a3/a4 30.7.16 dma configuration register name: dma access type: read/write offset: 0x050 reset value: 0x00000000 ? dmaen: dma hardware handshaking enable 1: dma interface is enabled. 0: dma interface is disabled. to avoid unpredictable behavior, dma hardware handshaking must be disabled when cpu transfers are performed. to avoid data losses, the dma register should be initialized befo re sending the data transfer command. this is also illustrated in figure 30-10 on page 843 or figure 30-11 on page 845 ? chksize: dma channel read and write chunk size the chksize field indicates the number of data available when the dma chunk transfer request is asserted. ? offset: dma write buffer offset this field indicates the number of discarded bytes w hen the dma writes the first word of the transfer. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------damen 76543210 - chksize - - offset chksize value number of data transferred 0 1 only available if fifo_size>= 16 bytes 1 4 only available if fifo_size>= 32 bytes 2 8 only available if fifo_size>= 64 bytes 3 16 only available if fifo_size>= 128 bytes 4 32 only available if fifo_size>= 256 bytes others - reserved
876 32072d?04/2011 at32uc3a3/a4 30.7.17 configuration register name: cfg access type: read/write offset: 0x054 reset value: 0x00000000 ? lsync: synchronize on the last block 1: the pending command is sent at the end of the block transfer when the transfer length is not infinite. (block count shall be different from zero) 0: the pending command is sent at the end of the current data block. this register needs to configured befor e sending the data transfer command. ? hsmode: high speed mode 1: the host controller outputs comm and line and data lines on the rising edge of t he card clock. the host driver shall check th e high speed support in the card registers. 0: default bus timing mode. ? ferrctrl: flow error bit reset control mode 1: when an underflow/overflow condition bit is set, reading sr resets the bit. 0: when an underflow/overflow condition bit is set, a new write/read command is needed to reset the bit. ? fifomode: mci internal fifo control mode 1: a write transfer starts as soon as one data is written into the fifo. 0: a write transfer starts when a sufficien t amount of data is wr itten into the fifo. when the block length is greater than or equal to 3/4 of the mc i internal fifo size, then the write transfer starts as soon as half the fifo is filled. when the block length is greater than or equal to half the internal fifo size, then the write transfer star ts as soon as one quarter of the fifo is filled. in other cases, the transfer starts as soon as the total amount of data is written i n the internal fifo. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 ---lsync---hsmode 76543210 - - - ferrctrl - - - fifomode
877 32072d?04/2011 at32uc3a3/a4 30.7.18 write protect mode register name: wpmr access type: read/write offset: 0x0e4 reset value: 0x00000000 ? wpkey[23:0]: write protection key password this field should be written at value 0x4d4349 (ascii code for ?mci?). writing any other value in this field has no effect. ? wpen: write protection enable 1: this bit enables the write protection if wpkey corresponds. 0: this bit disables the write protection if wpkey corresponds. 31 30 29 28 27 26 25 24 wpkey[23:16] 23 22 21 20 19 18 17 16 wpkey[15:8] 15 14 13 12 11 10 9 8 wpkey[7:0] 76543210 -------wpen
878 32072d?04/2011 at32uc3a3/a4 30.7.19 write protect status register name: wpsr access type: read-only offset: 0x0e8 reset value: 0x00000000 ? wpvsrc[15:0]: write protec tion violation source this field contains address where the violation access occurs. ? wpvs: write protection violation status 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 wpvsrc[15:8] 15 14 13 12 11 10 9 8 wpvsrc[7:0] 76543210 ---- wpvs wpvs definition 0 no write protection violation occu rred since the last read of this register (wpsr) 1 write protection detected unauthorized attempt to write a control register had occurred (s ince the last read.) 2 software reset had been performed while write protection was enabled (since the last read). 3 both write protection violation and software reset with write protection enabled had occurred since the last read. others reserved
879 32072d?04/2011 at32uc3a3/a4 30.7.20 version register name: version access: read-only offset: 0x0fc reset value: - ? variant: variant number reserved. no functionality associated. ? version: version number version number of the module. no functionality associate 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ----- variant 15 14 13 12 11 10 9 8 - - - - version[11:8] 76543210 version[7:0]
880 32072d?04/2011 at32uc3a3/a4 30.7.21 fifo memory aperture name: - access: read/write offset: 0x200 - 0x3ffc reset value: 0x000000000 ? data[31:0]:data to read or data to write 31 30 29 28 27 26 25 24 data[31:24] 23 22 21 20 19 18 17 16 data[23:16] 15 14 13 12 11 10 9 8 data[15:8] 76543210 data[7:0]
881 32072d?04/2011 at32uc3a3/a4 30.8 module configuration the specific configuration for the mci instance is listed in the following tables.the module bus clocks listed here are connected to the system bus clocks according to the table in the power manager section. table 30-8. module clock name module name clock name mci clk_mci table 30-9. parameter value name value fifo_size 128 table 30-10. register reset values register reset value version 0x00000410
882 32072d?04/2011 at32uc3a3/a4 31. memory stick interface (msi) rev: 2.1.0.0 31.1 features ? memory stick ver. 1.x & memory stick pro support ? memory stick serial clock (serial mode: 20 mhz max., parallel mode: 40 mhz max.) ? data transmit/receive fifo of 64 bits x 4 ? 16 bits crc circuit ? dmaca transfer support ? card insertion/removal detection 31.2 overview the memory stick interface (msi) is a host cont roller that supports memory stick version 1.x and memory stick pro. the communication protocol with the memory stick is started by write from the cpu to the com- mand register. when the protocol finishes, the cp u is notified that the protocol has ended by an interrupt request. when the protocol is started and enters the data transfer state, data is requested by issuing a dma transfer request (via dmaca) or an interrupt request to the cpu. the rdy time out time when the handshake state (bs2 in read protocol, bs3 for write protocol) is established in communication with the memo ry stick can be designated as the number of memory stick transfer clocks. when a time out occu rs, the cpu is notified that the protocol has ended due to a time out error by an interrupt request. crc circuit can be set off for test mode purpose. when crc is off, crc is not added to the data transmitted to the memory stick. an interrupt request can also be issued to the cpu when a memory stick is inserted or removed. figure 31-1. read packet rdy/bsy crc data tpc int int bs0 bs1 bs2 bs3 bs0 bs sdio / data[3:0] sclk memory stick host memory stick
883 32072d?04/2011 at32uc3a3/a4 figure 31-2. write packet 31.3 block diagram figure 31-3. msi block diagram 31.4 product dependencies 31.4.1 gpio sclk, data[3..0], bs & ins are i/o lines, multiplexed with other i/o lines. the i/o controller must be configured so that msi can drive these i/o lines. 31.4.2 power manager msi is clocked through the power manager (pm), thus programmer must first configure the pm to enable the clk_msi clock. rdy/bsy crc data tpc int int bs0 bs1 bs2 bs3 bs0 bs sdio / data[3:0] sclk memory stick host memory stick data buffer ms i/f fifo 64 x 4 registers pb clk_msi data3 data2 data1 sdio / data0 sclk ins bs
884 32072d?04/2011 at32uc3a3/a4 31.4.3 interrupt controller msi interrupt line is connected to the interrupt controller. in order to handle interrupts, interrupt controller(intc) must be programmed before configuring msi. 31.4.4 dma controller (dmaca) handshake signals are connected to dmaca. in or der to accelerate transfer from/to flash card, dmaca must be programmed before using msi. 31.5 connection to a memory stick the memory stick serial clock (sclk) is maximum 20 mhz in serial mode, and maximum 40 mhz in parallel mode. sclk is derived from peripheral clock (clk_msi) : f_sclk = f_clk_msi / [2*(clkdiv+1)] where clkdiv = {0..255}. pin data[1] is a power supply for some memory st ick version, so leaving the pull-down resistor connected may result in wasteful current cons umption. user should leave the data[1] pin pull- down open when memory stick ver. 1.x is inserted. table 31-1. memory stick pull-do wn configuration figure 31-4. memory stick pull-down overview memory stick 1.x memory stick pro memory stick inserted pull-down open pull-down enabled memory stick removed pull-down enabled pull-down enabled
885 32072d?04/2011 at32uc3a3/a4 31.6 functional description 31.6.1 reset operation an internal reset (initialization of the inte rnal registers and operating sequence) is performed when pb reset is active or by setting sys.rst=1. rst bit is cleared to 0 after the internal reset is completed. the protocol currently being executed stops, and the internal operating sequence is initialized. in addition, the fifo is set to the empty state (sr.emp=1, sr.ful=0). however, when the host controller is reset dur ing communication with the memory stick, the resulting bus state may differ from the memory stick. therefore, when reset is performed during communication, also power-on-reset the memory stick. internal registers are initialized to their initial value. however, some bits in following registers are not affected by rst bit : ? sys : clkdiv[7:0], ?isr : all bits but drq, ?sr : ista, ?imr : all bits. 31.6.2 communication with the memory stick an example of communication with the memory st ick is shown below. this example shows the case when transfer protocol command (tpc) set_cmd is executed. ? enable pend and msint interrupt requests (write pend=1, msint=1 in ier). ? set fifo direction to ?cpu to ms? (write fdir=1 in sys). ? write the command data to the fifo (write dat). ? write the tpc and the data transfer size to the command register to start the protocol (write cmd). ? after the protocol ends, an interrupt request is output from the host controller (pend=1 in isr). to acknowledge this inte rrupt request, cpu must clear the source of interrupt by writing pend=1 in iscr. ? some tpc commands require additional time to be executed by memory stick therefore int can appear later after protocol end. after int generation, an interrupt request is output from the host controller (msint=1 in isr). to acknowledge this interrupt request, cpu must clear the source of interrupt by writing msint=1 in iscr. when the command register is written, the communication protocol with the memory stick starts and data transmit/receive is performed. the data transfer direction is determined from tpc[3]. when tpc[3]=0, the read protocol is per- formed, and when tpc[3]=1, the write protocole is performed. when tpc[3] and fdir bit differ, the tpc[3] value is reflected to system register bit fdir when the protocol starts. fifo can be written after protocol start theref ore data must be written each time isr.drq=1. even when the data is less than 8 bytes, always read and write 8 bytes of data. all interrupt
886 32072d?04/2011 at32uc3a3/a4 sources can be cleared by setting corresponding bit in iscr but drq which is cleared once fifo has been read/written. figure 31-5. communication example 31.6.3 parallel interface mode setting procedure host controller supports parallel mode and must be set to pa rallel interface mode after the mem- ory stick. ? identify the memory stick media and confirm it is a memory stick pro. for memory stick media identification, see ?memory stick standard format specifications ver. 1.x appendix d? or ?memory stick standard format specifications ver. 2.0 application notes 1.3 media identification process?. ? set the memory stick to parallel interface mode by executing tpc commands set_r/w_reg_adrs then write_reg to set system parameter bit pam=1. ? write srac=0 and rei=0 to the system regi ster (sys) to switch host controller to parallel interface mode. ? change serial clock (sclk) while communication is not being performed with the memory stick. fifo direction setting write to fifo tpc setting interrupt wait mssys register msdat register mscmd register protocol start fdir=1 cmd tpc = set_cmd cpu msi communication with memory stick protocol end msiscr register interrupt enable msier register pend=1, msint=1 msisr.pend=1 interrupt clear pend=1 interrupt wait interrupt clear ms int wait int from memory stick int received msisr.msint=1 msiscr register msint=1
887 32072d?04/2011 at32uc3a3/a4 figure 31-6. interface mode switching sequence 31.6.4 data transfer requests after the communication protocol with the memory stick starts, a data transfer request is asserted to the cpu (drq bit in isr) and to dmaca (internal signals), until data transfer of the amount indicated by dsz (cmd) is finished. however, the data transfer request stops when the internal fifo becomes either empty or full. like cpu, dmaca uses peripheral bus to access fifo so it is not recommended to access msi registers during transfer. it is also not recommended to enable drq interrupt because isr.drq bit is automatically cleared when fifo is accessed. dmaca channel should be configured first and the data size should be a multiple of 64 bits (fifo size is 4 * 64bits). 31.6.5 interrupts the interrupt sources of msi are : ? pend : protocol command ended without error. ? drq : data request, fifo is full or empty. ? msint : interrupt received from memory stick. ? crc : protocol ended with crc error. ? toe : protocol ended with time out error. ? cd : card detected (inserted or removed). each interrupt source can be enabled in interrupt enable register (ier) and disabled in interrupt disable register (idr). the enable status is read in interrupt mask register (imr). the status of the interrupt source, even if the interrupt is masked, can be read in isr. write_reg tpc system parameter (pam bit) set_r/w_reg_adrs tpc set parallel interface mode ( mssys.srac=0, mssys.rei=0) serial interface mode ( mssys.srac=1, mssys.rei=1) error ok change sclk ( mssys.clkdiv[7:0]=x)
888 32072d?04/2011 at32uc3a3/a4 drq interrupt request is cleared by reading (recept ion) or writing (transmission) fifo, other interrupt requests are cleared by writing 1 to the corresponding bit in interrupt status clear reg- ister (iscr). 31.6.6 ocd mode there is no ocd mode for msi. 31.7 user interface table 31-2. msi register memory map offset register name access reset state 0x0000 command register cmd read/write 0x00000000 0x0004 data register dat read/write 0x4c004c00 0x0008 status register sr read only 0x00001020 0x000c system register sys read/write 0x00004015 0x0010 interrupt status register isr read only 0x00000000 0x0014 interrupt status clear register iscr write only 0x00000000 0x0018 interrupt enable register ier write only 0x00000000 0x001c interrupt disable register idr write only 0x00000000 0x0020 interrupt mask register imr read only 0x00000000 0x0024 version register version read only 0x00000210
889 32072d?04/2011 at32uc3a3/a4 31.7.1 command register name : cmd access type : read/write offset : 0x00 reset value : 0x00000000 ? tpc : transfer protocol code. tpc[3] indicates the transfer direction of data (1:write packet, 0:read packet) ? dsl : data select. 0 : data is transmitted to and received from memory stick using the internal fifo. 1 : reserved. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 tpc - dsl dsz 76543210 dsz code (dec) tpc description 2 read_long_data transfer data from data buffer (512 bytes) 3 read_short_data transfer data from data buffer (32~256 bytes) 4 read_reg read from a register 7get_int read from an int register 8 set_r/w_reg_adrs set an address of read_reg/write_reg 9 ex_set_cmd set command and parameters 11 write_reg write to a register 12 write_short_data transfer data to data buffer (32~256 bytes) 13 write_long_data transfer data to data buffer (512 bytes) 14 set_cmd set command other - banned for use
890 32072d?04/2011 at32uc3a3/a4 ? dsz : data size. length can be set from 1 byte to 1024 bytes. however, 1024 bytes is set when dsz=0.
891 32072d?04/2011 at32uc3a3/a4 31.7.2 data register name : dat access type : read/write offset : 0x04 reset value : 0x4c004c00 this register is used to acces internal fifo. even when the data is less than 8 bytes, always read and write 8 bytes of data. 31 30 29 28 27 26 25 24 data 23 22 21 20 19 18 17 16 data 15 14 13 12 11 10 9 8 data 76543210 data
31.7.3 status register name : sr access type : read only offset : 0x08 reset value : 0x00001020 ? ista : insertion status. it reflects the memory st ick card presence. this is the inverse of ins pin. 0 : no card. 1 : card is inserted. ? rdy : ready. rdy goes to 1 when the protocol ends. this bi t bit is cleared to 0 by wr ite to the command register. 0 : command receive disabled due to communication with the memory stick. 1 : command received or protocol ended. ? emp : fifo empty. this bit is set to 1 by writing system register bit fclr=1. 0 : fifo contains data. 1 : fifo is empty. ? ful : fifo full. this bit is cleared to 0 by writing system register bit fclr=1. 0 : fifo has empty space. 1 : fifo is full. ? ced : ms command end. in parallel mode, this bit reflects the ced bit in the status register of a memory stick (int). indicates the end of a command executed with set_cmd tpc. in serial mode, this bit is always 0. it is cleared to 0 by writing to the command register (cmd). ? err : memory stick error. in parallel mode, this bit reflects the err bit in the status register of a memory stick (int). it indicates the occurence of an error. in serial mode, this bit is always 0. it is cleared to 0 by writing to the command register (cmd). 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------ista 15 14 13 12 11 10 9 8 ---rdy---- 76543210 - - emp ful ced err brq cnk
893 32072d?04/2011 at32uc3a3/a4 ? brq : ms data buffer request. in parallel mode, this bit reflects the breq bit in the status register of a memory stick (int). it indicates that a host has requested to access a memory sticks page buffer.in serial mode , this bit is always 0. it is cleared to 0 by writing to the command register (cmd). ? cnk : ms command no acknowledge. in parallel mode, this bit reflects the cm dnk bit in the status register of a memory stick (int). it indicates that the command cannot be executed. in serial mode, this bit is always 0. it is cleared to 0 by writing to the command register (cmd).
31.7.4 system register name : sys access type : read/write offset : 0x0c reset value : 0x00004015 ? clkdiv : clock division. write this field to change sclk frequency = clk_msi / (2*(clkdiv+1)). ? rst : reset. when rst is written, in ternal synchronous reset is performed. 0 : this bit is cleared to 0 after the internal reset is completed. 1 : writing a 1 starts reset operation. ? srac : serial access mode. the srac can not be changed duri ng protocol execution. 0 : write this bit to 0 to set parallel mode. 1 : write this bit to 1 to set serial mode. ? nocrc : no crc computation. 0 : write 0 to enable crc output. during read protocol, the crc check is performed as usual regardless of nocrc. 1 : write 1 to disable crc output. when nocrc=1, the write protocol is executed without adding the crc data. ? fclr : fifo clear. write 1 to initialize fifo dat a. this bit is cleared afte r the fifo is initialized. ? fdir : fifo direction. 0 : write 0 to set the fifo direction to transmit. 1 : write 1 to set the fifo direction to receive. ? rei : rising edge input. when setting parallel mode, set re i=0. this setting cannot be changed during protocol execution. 0 : write 0 to sample data at the falling edge of sclk. 1 : write 1 to sample data at the rising edge of sclk. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 clkdiv 15 14 13 12 11 10 9 8 rst srac - nocrc - - fclr fdir 76543210 - - - rei reo bsy
895 32072d?04/2011 at32uc3a3/a4 ? reo : rising edge output. this bit is used when not fixed hold time by the side of the memory stick in parallel communication. this setting cannot be changed during protocol execution. 0 : write 0 to synchronize outputs with the falling edge of sclk. 1 : write 1 to synchronize outputs with the rising edge of sclk. ? bsy : busy count. this is the maximum bsy wait time un til the rdy signal is outp ut from the memory stick. 0 : write a value to configure time out = bsy * 4 sclk. 1 : write 0 to disable time out detection.
31.7.5 interrupt status register name : isr access type : read only offset : 0x10 reset value : 0x00000000 ? cd : card detection. 0 : no card detected. this bit is cleared when the correponding bit in iscr is set to 1. 1 : this bit is set to 1 when a memory stick card is inserted or removed. ? toe : time out error. 0 : this bit is cleared to 0 when the corresponding bit in iscr it set to 1. 1 : this bit is set to 1 when protol ended with time out error. ? crc : crc error. 0 : no crc error. this bit is cleared when the corresponding bit in iscr is set to 1. 1 : this bit is set when protocol ends with crc error. ? msint : memory stick interruption. 0 : this bit is cleared to 0 when the corresponding bit in iscr is set to 1. 1 : this bit is set to 1 when an interrupt request int is received from memory stick. ? drq : data request, fifo is full (r eception) or empty (transmission). 0 : this bit is cleared to 0 when data access is no more required. 1 : this bit is set to 1 when data access is required (read or write). ? pend : protocol end. 0 : this bit is cleared to 0 when the corresponding bit in iscr is set to 1. 1 : this bit is set to 1 when protol ended witout error. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - cd toe crc msint drq pend
897 32072d?04/2011 at32uc3a3/a4 31.7.6 interrupt status clear register name : iscr access type : write only offset : 0x14 reset value : 0x00000000 ? cd : card detection clear bit. 0 : writing 0 has no effect. 1 : writing 1 clears corresponding bit in isr. ? toe : time out error clear bit. 0 : writing 0 has no effect. 1 : writing 1 clears corresponding bit in isr. ? crc : crc error clear bit. 0 : writing 0 has no effect. 1 : writing 1 clears corresponding bit in isr. ? msint : memory stick interruption clear bit. 0 : writing 0 has no effect. 1 : writing 1 clears corresponding bit in isr. ? pend : protocol end clear bit. 0 : writing 0 has no effect. 1 : writing 1 clears corresponding bit in isr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - cd toe crc msint - pend
31.7.7 interrupt enable register name : ier access type : write only offset : 0x18 reset value : 0x00000000 ? cd : card detection interrupt enable. 0 : writing 0 has no effect. 1 : writing 1 set to 1 corresponding bit in imr. ? toe : time out error interrupt enable. 0 : writing 0 has no effect. 1 : writing 1 set to 1 corresponding bit in imr. ? crc : crc error interrupt enable. 0 : writing 0 has no effect. 1 : writing 1 set to 1 corresponding bit in imr. ? msint : memory stick interrupt enable. 0 : writing 0 has no effect. 1 : writing 1 set to 1 corresponding bit in imr. ? drq : data request interrupt enable. 0 : writing 0 has no effect. 1 : writing 1 set to 1 corresponding bit in imr. ? pend : protocol end interrupt enable. 0 : writing 0 has no effect. 1 : writing 1 set to 1 corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - cd toe crc msint drq pend
899 32072d?04/2011 at32uc3a3/a4 31.7.8 interrupt disable register name : idr access type : write only offset : 0x1c reset value : 0x00000000 ? cd : card detection interrupt disable. 0 : writing 0 has no effect. 1 : writing 1 clears to 0 corresponding bit in imr. ? toe : time out error interrupt disable. 0 : writing 0 has no effect. 1 : writing 1 clears to 0 corresponding bit in imr. ? crc : crc error interrupt disable. 0 : writing 0 has no effect. 1 : writing 1 clears to 0 corresponding bit in imr. ? msint : memory stick interrupt disable. 0 : writing 0 has no effect. 1 : writing 1 clears to 0 corresponding bit in imr. ? drq : data request interrupt disable. 0 : writing 0 has no effect. 1 : writing 1 clears to 0 corresponding bit in imr. ? pend : protocol end interrupt disable. 0 : writing 0 has no effect. 1 : writing 1 clears to 0 corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - cd toe crc msint drq pend
31.7.9 interrupt mask register name : imr access type : read only offset : 0x20 reset value : 0x00000000 ? cd : card detection interrupt mask. 0 : interrupt is disabled. 1 : interrupt is enabled. ? toe : time out error interrupt mask. 0 : interrupt is disabled. 1 : interrupt is enabled. ? crc : crc error interrupt mask. 0 : interrupt is disabled. 1 : interrupt is enabled. ? msint : memory stick interrupt mask. 0 : interrupt is disabled. 1 : interrupt is enabled. ? drq : data request interrupt mask. 0 : interrupt is disabled. 1 : interrupt is enabled. ? pend : protocol end interrupt mask. 0 : interrupt is disabled. 1 : interrupt is enabled. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 - - cd toe crc msint drq pend
901 32072d?04/2011 at32uc3a3/a4 31.7.10 version register name : version access type : read only offset : 0x24 reset value : 0x00000210 ? variant: variant number reserved. no functionality associated. ? version : version number version number of the module. no functionality associated. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ---- variant 15 14 13 12 11 10 9 8 ---- version[11:8] 76543210 version[7:0]

903 32072d?04/2011 at32uc3a3/a4

905 32072d?04/2011 at32uc3a3/a4

907 32072d?04/2011 at32uc3a3/a4 32. advanced encryption standard (aes) rev: 1.2.3.1 32.1 features ? compliant with fips publication 197, advanced encryption standard (aes) ? 128-bit/192-bit/256-bit cryptographic key ? 12/14/16 clock cycles encryption/decryption pr ocessing time with a 128-bit/192-bit/256-bit cryptographic key ? support of the five standard mode s of operation sp ecified in the nist special publication 800- 38a, recommendation for bloc k cipher modes of operation - methods and techniques: ? electronic code book (ecb) ? cipher block chaining (cbc) ? cipher feedback (cfb) ? output feedback (ofb) ? counter (ctr) ? 8-, 16-, 32-, 64- and 128-bit data size possible in cfb mode ? last output data mode allows optimized message authentication code (mac) generation ? hardware counter measures against di fferential power analysis attacks ? connection to dma controller capabilities opti mizes data transfers fo r all operating modes 32.2 overview the advanced encryption standard (aes) is compliant with the american fips (federal infor- mation processing standard) publication 197 specification. the aes supports all five confidentiality modes of operation for symmetrical key block cipher algorithms (ecb, cbc, ofb, cfb and ctr), as specified in the nist special publication 800- 38a recommendation. it is compatible with all these modes via dma controller, minimizing pro- cessor intervention for large buffer transfers. the 128-bit/192-bit/256-bit key is stored in write- only four/six/eight 32-bit key word registers (keywnr) which are all write-only registers. the 128-bit input data and initialization vector (for some modes) are each stored in 32-bit input data registers (idatanr) and in initialization ve ctor registers (vnr) which are all write-only registers. as soon as the initialization vector, the input data and the key are configured, the encryp- tion/decryption process may be started. then the encrypted/decrypted data is ready to be read out on the four 32-bit output data registers (odatanr) or through the dma controller. 32.3 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 32.3.1 power management if the cpu enters a sleep mode th at disables clocks used by the aes, the aes will stop function- ing and resume operation after the system wakes up from sleep mode.
908 32072d?04/2011 at32uc3a3/a4 32.3.2 clocks the clock for the aes bus interface (clk_aes) is generated by the powe r manager. th is clock is enabled at reset, and can be disabled in the power manager. it is recommended to disable the aes before disabling the clo ck, to avoid freezing the aes in an undefined state. 32.3.3 interrupts the aes interrupt requ est line is connected to the interrup t controller. using the aes interrupt requires the interrupt controller to be programmed first. 32.4 functional description the aes specifies a fips-approved cryptographic algorithm that can be used to protect elec- tronic data. the aes algorithm is a symmetric block cipher that can encrypt (encipher) and decrypt (decipher) information. encryption converts data to an unintelligible form called ciphertext. decrypting the ciphertext converts the data back into its original form, called plaintext. the processing mode bit in the mode register (mr.cipher) allows selectio n between the encryption and the decryption processes. the aes is capable of usin g cryptographic keys of 128/ 192/256 bits to encr ypt and decrypt data in blocks of 128 bits. this 128-bit/192-bit/256-bit key is defined in the keywnr registers (keywnr). the input to the encryption processes of the cbc, cfb, and ofb modes includes, in addition to the plaintext, a 128-bit data block called the initia lization vector, which must be writing in the ini- tialization vector registers (ivnr). the initializ ation vector is used in an initial step in the encryption of a message and in the corresponding decryption of the message. the ivrnr regis- ters are also used in the ctr mode to set the counter value. 32.4.1 operation modes the aes supports the following modes of operation: ? ecb: electronic code book ? cbc: cipher block chaining ? ofb: output feedback ? cfb: cipher feedback ? cfb8 (cfb where the length of the data segment is 8 bits) ? cfb16 (cfb where the length of the data segment is 16 bits) ? cfb32 (cfb where the length of the data segment is 32 bits) ? cfb64 (cfb where the length of the data segment is 64 bits) ? cfb128 (cfb where the length of the data segment is 128 bits) ?ctr: counter the data pre-processing, post-processing and chaining for the concerned modes are automati- cally performed. refer to the nist special publication 800-38a recommendation for more complete information. these modes are selected by writing the operation mode field in the mode register (mr.opmod). in cfb mode, five data size are possible (8 bits, 16 bits, 32 bits, 64 bits or 128 bits).
909 32072d?04/2011 at32uc3a3/a4 these sizes are selected by writing the cipher feedback data size field in the mr register (mr.cfds). 32.4.2 start modes the start mode field in the mr register (mr.smod) allows selection of the encryption (or decryption) start mode. 32.4.2.1 manual mode the sequence is as follows: ? write the 128-bit/192- bit/256-bit key in the keywnr registers. ? write the initialization vector (or counter) in the ivnr registers. note: the initialization vector registers concern all modes except ecb. ? write the data ready bit in the interrupt enable register (ier.datrdy), depending on whether an interrupt is required or not at the end of processing. ? write the data to be encrypted/decrypted in the authorized input data registers (idatanr). note: in 64-bit cfb mode, writing to idata3r and idata4r registers is not allowed and may lead to errors in processing. note: in 32-bit, 16-bit and 8-bit cfb modes, writing to idata2r, idata3r and idata4r registers is not allowed and may lead to errors in processing. ? write the start bit in the control register (cr.start) to begin the encryption or the decryption process. ? when the processing completes, the datrdy bit in the interrupt status register (isr.datrdy) is set. ? if an interrupt has been enabled by writing th e ier.datrdy bit, the interrupt line of the aes is activated. ? when the software reads one of the output data registers (odataxr), the isr.datrdy bit is cleared. 32.4.2.2 automatic mode the automatic mode is similar to the manual one, except that in this mode, as soon as the cor- rect number of idatanr registers is written, processing is automatically started without any action in the cr register. table 32-1. authorized input data registers operation mode idatanr to write ecb all cbc all ofb all 128-bit cfb all 64-bit cfb idata1r and idata2r 32-bit cfb idata1r 16-bit cfb idata1r 8-bit cfb idata1r ctr all
910 32072d?04/2011 at32uc3a3/a4 32.4.2.3 dma mode the dma controller can be used in association with the aes to perform an encryption/decryp- tion of a buffer without any action by the software during processing. in this starting mode, the type of the data transfer (byte, halfword or word) depends on the oper- ation mode. the sequence is as follows: ? write the 128-bit/192- bit/256-bit key in the keywnr registers. ? write the initialization vector (or counter) in the ivnr registers. note: the initialization vector registers concern all modes except ecb. ? configure a channel of the dma controller with source address (data buffer to encrypt/decrypt) and destination address set to register idata1r (index is automatically incremented and rolled over to write idatanr). then configure a second channel with source address set to odata1r (index is automatically incremented and rolled over to read odatanr) and destination address to write processed data. note: transmit and receive buffers can be identical. ? enable the dma controller in transmission and reception to start the processing. ? the processing completion should be monitored with the dma controller. 32.4.3 last output data mode this mode is used to generate cryptographi c checksums on data (mac ) by means of cipher block chaining encryption algorithm (cbc-mac algorithm for example). after each end of encryption/decryption, the out put data is available either on the odatanr registers for manual and automatic mode or at the address specified in the receive buffer pointer for dma mode. the last output data bit in the mode register (mr.lod) allows retrieval of only the last data of several encryption/de cryption processes. therefore, there is no need to define a read buffer in dma mode. this data is only available on the output data registers (odatanr). table 32-2. data transfer type for the different operation modes operation mode data transfer type (dma) ecb word cbc word ofb word cfb 128-bit word cfb 64-bit word cfb 32-bit word cfb 16-bit halfword cfb 8-bit byte ctr word
911 32072d?04/2011 at32uc3a3/a4 32.4.3.1 manual and automatic modes ? when mr.lod is zero the isr.datrdy bit is cleared when at l east one of the odatanr registers is read. figure 32-1. manual and automatic modes when mr.lod is zero if the user does not want to read the output data registers between each encryption/decryption, the isr.datrdy bit will not be cleared. if the is r.datrdy bit is not cl eared, the us er cannot know the end of the following encryptions/decryptions. ? when mr.lod is one the isr.datrdy bit is cleared when at least one idatanr register is wr itten, so before the start of a new transfer. no more odatanr register reads are necessary between consecutive encryptions/decryptions. figure 32-2. manual and automatic modes when mr.lod is one 32.4.3.2 dma mode ? when mr.lod is zero the end of the encryption/decryption should be monitored with the dma controller. write cr.start (manual mode) or write idatanr register(s) (auto mode) isr.datrdy encryption or decryption process read odatanr register(s) write idatanr register(s) encryption or decryption process write cr.start(manual mode) or write idatanr register(s) (auto mode) isr.datrdy
912 32072d?04/2011 at32uc3a3/a4 figure 32-3. dma mode when mr.lod is zero ? when mr.lod is one the user must first wait for the dma controlle r interrupt, then for isr.datrdy to ensure that the encryption/decryption is completed. in this case, no receive buffers are required. the output data is only available in odatanr registers. figure 32-4. dma mode when mr.lod is one following table summarizes the different cases. note: 1. depending on the mode, there are other ways of clearing the datrdy.isr bit. see the interrupt status register (isr) definition. warning: in dma mode, reading to the odatanr registers before the last data transfer may lead to unpredictable results. dma controller interrupt multiple encryption or decryption processes enable dma controller channels (receive and transmit channels) enable dma controller channels (only transmit channel) isr.datrdy multiple encryption or decryption processes dma controller interrupt table 32-3. last output mode behavior versus start modes manual and automatic modes dma mode mr.lod = 0 mr.lod = 1 mr.lod = 0 mr.lod = 1 isr.datrdy bit clearing condition (1) at least one odatanr register must be read at least one idatanr register must be written not used managed by the dma controller encrypted/decrypted data result location in odatanr registers in odatanr registers at the address specified in the configuration of dma controller in odatanr registers end of encryption/ decryption isr.datrdy isr.datrdy dma controller interrupt dma controller interrupt then datrdy.isr
913 32072d?04/2011 at32uc3a3/a4 32.4.4 security features 32.4.4.1 countermeasures the aes also features hardware c ountermeasures that can be useful to protect data against dif- ferential power analysis (dpa) attacks. these countermeasures can be enabled through th e countermeasure type field in the mr reg- ister (mr.ctype). this field is write-only, and all changes to it are taken into account if, at the same time, the countermeasure key field in the mode register (mr.ckey) is correctly written (see the mode register (mr) description in section 32.5.2 ). note: enabling countermeasures has an impact on the aes encryption/decryption throughput. by default, all the countermeasures are enabled. the best throughput is achieved with all the c ountermeasures disabled. on the other hand, the best protection is achieved with all of them enabled. the random number generat or seed loading bit in the cr register (cr.loadseed) allows a new seed to be loaded in the embedded random number generator used for the different countermeasures. 32.4.4.2 unspecified regi ster access detection when an unspecified register access occurs, the unspecified register detection status bit in the isr register (isr.urad) is set to one. its s ource is then reported in the unspecified register access type field in the isr register (isr.urat) . only the last unspecified register access is available through the isr.urat field. several kinds of unspecified register accesses can occur when: ? writing the idatanr registers during the data processing in dma mode ? reading the odatanr registers during data processing ? writing the mr register during data processing ? reading the odatanr registers during sub-keys generation ? writing the mr register during sub-keys generation ? reading an write-only register the isr.urad bit and the isr.urat field can only be reset by the software reset bit in the cr register (cr.swrst).
914 32072d?04/2011 at32uc3a3/a4 32.5 user interface note: 1. the reset value are device specific. please refer to th e module configuration section at the end of this chapter. table 32-4. aes register memory map offset register register name access reset 0x00 control register cr write-only 0x00000000 0x04 mode register mr read/write 0x00000000 0x10 interrupt enable register ier write-only 0x00000000 0x14 interrupt disable register idr write-only 0x00000000 0x18 interrupt mask register imr read-only 0x00000000 0x1c interrupt status register isr read-only 0x0000001e 0x20 key word 1 register keyw1r write-only 0x00000000 0x24 key word 2 register keyw2r write-only 0x00000000 0x28 key word 3 register keyw3r write-only 0x00000000 0x2c key word 4 register keyw4r write-only 0x00000000 0x30 key word 5 register keyw5r write-only 0x00000000 0x34 key word 6 register keyw6r write-only 0x00000000 0x38 key word 7 register keyw7r write-only 0x00000000 0x3c key word 8 register keyw8r write-only 0x00000000 0x40 input data 1 register idata1r write-only 0x00000000 0x44 input data 2 register idata2r write-only 0x00000000 0x48 input data 3 register idata3r write-only 0x00000000 0x4c input data 4 register idata4r write-only 0x00000000 0x50 output data 1 register odata1r read-only 0x00000000 0x54 output data 2 register odata2r read-only 0xc01f0000 0x58 output data 3 register odata3r read-only 0x00000000 0x5c output data 4 register odata4r read-only 0x00000000 0x60 initialization vector 1 register iv1r write-only 0x00000000 0x64 initialization vector 2 register iv2r write-only 0x00000000 0x68 initialization vector 3 register iv3r write-only 0x00000000 0x6c initialization vector 4 register iv4r write-only 0x00000000 0xfc version register vr read-only - (1)
915 32072d?04/2011 at32uc3a3/a4 32.5.1 control register name: cr access type: write-only offset: 0x00 reset value: 0x00000000 ? loadseed: random number generator seed loading writing a one to this bit will load a new seed in the embedded random number generator used for the different countermeasures. writing a zero to this bit has no effect. ? swrst: software reset writing a one to this bit will reset the aes. writing a zero to this bit has no effect. ? start: start processing writing a one to this bit will start manual encryption/decryption process. writing a zero to this bit has no effect. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 - - - - - - - loadseed 15 14 13 12 11 10 9 8 -------swrst 76543210 -------start
916 32072d?04/2011 at32uc3a3/a4 32.5.2 mode register name: mr access type: read/write offset: 0x04 reset value: 0x00000000 ? ctype: countermeasure type all the countermeasures are enabled by default. ctype field is write-only and can only be modified if ckey is correctly set. 31 30 29 28 27 26 25 24 - - - ctype 23 22 21 20 19 18 17 16 ckey - cfbs 15 14 13 12 11 10 9 8 lod opmod keysize smod 76543210 procdly - - - cipher ctype description xxxx0countermeasure type 1 is disabled xxxx1 add random spurious power consum ption during some configuration settings x x x 0 x countermeasure type 2 is disabled x x x 1 x add randomly 1 cycle to processing. x x 0 x x countermeasure type 3 is disabled x x 1 x x add randomly 1 cycle to processing (other version) x 0 x x x countermeasure type 4 is disabled x 1 x x x add randomly up to /13/15 cycles (f or /192/256-bit key) to processing 0xxxxcountermeasure type 5 is disabled 1xxxx add random spurious power consumption during processing (recommended with dma access)
917 32072d?04/2011 at32uc3a3/a4 ? ckey: countermeasure key writing the value 0xe to this field allows the ct ype field to be modified. writing another value to this field has no effect. this bit always reads as zero. ? cfbs: cipher feedback data size ? lod: last output data mode writing a one to this bit will enabled the lod mode. writing a zero to this bit will disabled the lod mode. these mode is described in the table 32-3 on page 912 . ? opmod: operation mode ? keysize: key size cfbs description 0 128-bit 1 64-bit 2 32-bit 3 16-bit 48-bit others reserved opmod description 0 ecb: electronic code book mode 1 cbc: cipher block chaining mode 2 ofb: output feedback mode 3 cfb: cipher feedback mode 4 ctr: counter mode others reserved keysize description 0 aes key size is 128 bits 1 aes key size is 192 bits others aes key size is 256 bits
918 32072d?04/2011 at32uc3a3/a4 ? smod: start mode ? procdly: processing delay the processing time represents the number of clock cycles that the aes needs in order to perform one encryption/decryption with no countermeasures activated: the best performance is achieved with procdly equal to 0. writing a value to this field will update the processing time. reading this field will give the current processing delay. ? cipher: processing mode 0: decrypts data is enabled. 1: encrypts data is enabled. smod description 0 manual mode 1 automatic mode 2 dma mode ? lod = 0: the encrypted/decrypted data are available at the address specified in the configuration of dma controller. ? lod = 1: the encrypted/decrypted data are available in the odatanr registers. 3 reserved processing time 12 procdly 1 + () =
919 32072d?04/2011 at32uc3a3/a4 32.5.3 interrupt enable register name: ier access type: write-only offset: 0x10 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will set the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------urad 76543210 -------datrdy
920 32072d?04/2011 at32uc3a3/a4 32.5.4 interrupt disable register name: idr access type: write-only offset: 0x14 reset value: 0x00000000 writing a zero to a bit in this register has no effect. writing a one to a bit in this register will clear the corresponding bit in imr. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------urad 76543210 -------datrdy
921 32072d?04/2011 at32uc3a3/a4 32.5.5 interrupt mask register name: imr access type: read-only offset: 0x18 reset value: 0x00000000 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. a bit in this register is cleared when the corresponding bit in idr is written to one. a bit in this register is set when the corresponding bit in ier is written to one. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------urad 76543210 -------datrdy
922 32072d?04/2011 at32uc3a3/a4 32.5.6 interrupt status register name: isr access type: read-only offset: 0x1c reset value: 0x0000001e ? urat: unspecified register access type: only the last unspecified register access type is available through the urat field. this field is reset to 0 when swrst bit in the control register is written to one. ? urad: unspecified register access detection status this bit is set when at least one unspecified register access has been detected since the last software reset. this bit is cleared when swrst bit in the control register is set to one. ? ? ? ? 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 urat - - - urad 76543210 -------datrdy urat description 0 the idatanr register during the data processing in dma mode. 1 the odatanr register read during the data processing. 2 the mr register written during the data processing. 3 the odatanr register read during the sub-keys generation. 4 the mr register written du ring the sub-keys generation. 5 write-only register read access. others reserved
923 32072d?04/2011 at32uc3a3/a4 ? datrdy: data ready this bit is set/clear as described in the table 32-3 on page 912 . this bit is also cleared when swrst bit in the control register is set to one.
924 32072d?04/2011 at32uc3a3/a4 32.5.7 key word n register name: keywnr access type: write-only offset: 0x20 +(n-1)*0x04 reset value: 0x00000000 ? keywn[31:0]: key word n writing the 128-bit/192-bit/256-bit cryptographic key used for enc ryption/decryption in the four /six/eight 32-bit key word registers. keyw1 corresponds to the first word of the key an d respectively keyw4/keyw6/ keyw8 to the last one. this field always read as zero to prevent t he key from being read by another application. 31 30 29 28 27 26 25 24 keywn[31:24] 23 22 21 20 19 18 17 16 keywn[23:16] 15 14 13 12 11 10 9 8 keywn[15:8] 76543210 keywn[7:0]
925 32072d?04/2011 at32uc3a3/a4 32.5.8 input data n register name: idatanr access type: write-only offset: 0x40 + (n-1)*0x04 reset value: 0x00000000 ? idatan[31:0]: input data word n writing the 128-bit data block used for encryption/dec ryption in the four 32-bit input data registers. idata1 corresponds to the first word of the data to be encrypted/decr ypted, and idata4 to the last one. this field always read as zero to prevent the in put data from being read by another application. 31 30 29 28 27 26 25 24 idatan[31:24] 23 22 21 20 19 18 17 16 idatan[23:16] 15 14 13 12 11 10 9 8 idatan[15:8] 76543210 idatan[7:0]
926 32072d?04/2011 at32uc3a3/a4 32.5.9 output data n register name: odatanr access type: read-only offset: 0x50 + (n-1)*0x04 reset value: 0x00000000 ? odatan[31:0]: output data n reading the four 32-bit odatanr give the 128-bit data block that has been encrypted/decrypted . odata1 corresponds to the first word, odata4 to the last one. 31 30 29 28 27 26 25 24 odatan[31:24] 23 22 21 20 19 18 17 16 odatan[23:16] 15 14 13 12 11 10 9 8 odatan[15:8] 76543210 odatan[7:0]
927 32072d?04/2011 at32uc3a3/a4 32.5.10 initializati on vector n register name: ivnr access type: write-only offset: 0x60 + (n-1)*0x04 reset value: 0x00000000 ? ivn[31:0]: initiali zation vector n the four 32-bit initialization vector registers set the 128-bit in itialization vector data block that is used by some modes of operation as an additional initial input: iv1 corresponds to the first word of the in itialization vector, iv4 to the last one. this field is always read as zero to prevent the init ialization vector from being read by another application. 31 30 29 28 27 26 25 24 ivn[31:24] 23 22 21 20 19 18 17 16 ivn[23:16] 15 14 13 12 11 10 9 8 ivn[15:8] 76543210 ivn[7:0] mode(opmode. description cbc,ofb, cfb initialization vector ctr counter value ecb not used, must not be written
928 32072d?04/2011 at32uc3a3/a4 32.5.11 version register name: version access type: read-only offset: 0xfc reset value: - ? variant: variant number reserved. no functionality associated. ? version[11:0] version number of the module. no functionality associated. 31 30 29 28 27 26 25 24 -------- 23 22 21 20 19 18 17 16 ---- variant 15 14 13 12 11 10 9 8 - - - - version[11:8] 76543210 version[7:0]
929 32072d?04/2011 at32uc3a3/a4 32.6 module configuration the specific conf iguration for each aes instan ce is listed in the followi ng tables.the module bus clocks listed here are connected to the system bus clocks according to the table in the system bus clock connections section. table 32-5. module clock name module name clock name aes clk_aes table 32-6. register reset values register reset value version 0x00000123
930 32072d?04/2011 at32uc3a3/a4 33. audio bitstream dac (abdac) rev: 1.0.1.1 33.1 features ? digital stereo dac ? oversampled d/a conversion architecture ? oversampling ratio fixed 128x ? fir equalization filter ? digital interpolation filter: comb4 ? 3rd order sigma-delta d/a converters ? digital bitstream outputs ? parallel interface ? connected to dma controller for backgrou nd transfer without cpu intervention 33.2 overview the audio bitstream dac converts a 16-bit samp le value to a digital bitstream with an average value proportional to the sample value. two channels are supported, making the audio bit- stream dac particularly suitable for stereo audio. each channel has a pair of complementary digital outputs, datan and datann, which can be connected to an external high input imped- ance amplifier. the output datan and datann should be as ideal as possible before filtering, to achieve the best snr and thd quality. the outputs can be connected to a class d amplifier output stage to drive a speaker directly, or it can be low pass filtered and connected to a high input impedance amplifier. a simple 1st order low pass filter that filters all the frequencies above 50khz should be adequate when applying the signal to a speaker or a bandlimited amplifier, as the speaker or amplifier will act as a filter and remove high frequency components from the signal. in some cases high frequency components might be folded down into the audible range, and in that case a higher order filter is required. for performance measurements on digital equipment a minimum of 4th order low pass filter should be used. this is to prevent aliasing in the measurements. for the best performance when not using a class d amplifier approach, the two outputs datan and datann, should be applied to a differential st age amplifier, as this will increase the snr and thd.
931 32072d?04/2011 at32uc3a3/a4 33.3 block diagram figure 33-1. abdac block diagram 33.4 i/o lines description 33.5 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. 33.5.1 i/o lines the output pins used for the output bitstream from the audio bitstream dac may be multiplexed with io lines. before using the audio bitstream dac, the i/o controller must be configured in order for the audio bitstream dac i/o lines to be in audio bitstream dac peripheral mode. table 33-1. i/o lines description pin name pin description type data0 output from audio bitstream dac channel 0 output data1 output from audio bitstream dac channel 1 output datan0 inverted output from audio bitstream dac channel 0 output datan1 inverted output from audio bitstream dac channel 1 output clock generator equalization fir comb (int=128) sigma-delta da-mod equalization fir comb (int=128) sigma-delta da-mod bit_clk data0 data1 gclk_abdac sample_clk channel0[15:0] audio bitstream dac pm user interface channel1[15:0]
932 32072d?04/2011 at32uc3a3/a4 33.5.2 clocks the clk_abdac to the audio bitstream dac is generated by the power manager (pm). before using the audio bitstream dac, the user must ensure that the audio bitstream dac clock is enabled in the power manager. the abdac needs a separate clock for the d/a conversion operation. this clock, gclk_abdac should be set up in the generic clock register in the power manager and its fre- quency must be as follow: where f s is the samping rate of the data stream to convert. for f s = 48khz this means that the gclk_abdac clock must have a frequency of 12.288mhz. the two clocks, clk_abdac and gclk_abdac, must be in phase with each other. 33.5.3 interrupts the abdac interrupt request line is connected to the interrupt controller. using the abdac interrupt requires the interrupt controller to be programmed first. 33.6 functional description 33.6.1 how to initialize the module in order to use the audio bitstream dac the product dependencies given in section 33.5 on page 931 must be resolved. particular attention should be given to the configuration of clocks and i/o lines in order to ensure correct operation of the audio bitstream dac. the audio bitstream dac is enabled by writing a one to the enable bit in the audio bitstream dac control register (cr.en). the transmit ready interrupt st atus bit in the interrupt stat us register (isr.txready) will be set whenever the abdac is ready to receive a new sample. a new sample value should be writ- ten to sdr before 256 abdac cl ock cycles, or an unde rrun will occur, as indicated by the underrun interrupt status bit in isr (isr.unde rrun). isr is cleared when read, or when writ- ing one to the corresponding bits in the interrupt clear register (icr). 33.6.2 data format the input data format is two?s complement. two 16-bit sample values for channel 0 and 1 can be written to the least and most significant halfword of the sample data register (sdr), respectively. an input value of 0x7fff will result in an output voltage of approximately: an input value of 0x8000 will result in an output value of approximately: f gclk 256 f s = v out 0 x 7 fff () 38 128 --------- - vddio 38 128 --------- - 33 , ? 0 98 v , = ? v out 0 x 8000 () 90 128 --------- - vddio 90 128 --------- - 33 , ? 2 32 v , = ?
933 32072d?04/2011 at32uc3a3/a4 if one want to get coherence between the sign of the input data and the output voltage one can use the datan signal or invert the sign of the input data by software. 33.6.3 data swapping when the swap bit in the abdac control register (cr. swap) is written to one, writing to the sample data register (sdr) will cause the values written to the channel0 and channel1 fields to be swapped. 33.6.4 peripheral dma controller the audio bitstream dac is connected to the peripheral dma controller. the peripheral dma controller can be programmed to automatically transfer samples to the audio bitstream dac sample data register (sdr) wh en the audio bitstream dac is ready for new samples. in this case only the cr.en bit needs to be set in the audio bitstream dac module. this enables the audio bitstream dac to operate without any cpu intervention such as polling the interrupt sta- tus register (isr) or using interrupts. see the peripheral dma controller documentation for details on how to setup peripheral dma transfers. 33.6.5 construction the audio bitstream dac is constructed of two 3rd order sigma-delta d/a converter with an oversampling ratio of 128. the samples are upsampl ed with a 4th order sinc interpolation filter (comb4) before being applied to the sigma-delta modulator. in order to compensate for the pass band frequency response of the interpolation filter and flatten the overall frequency response, the input to the interpolation filter is first filtered with a simple 3-tap fir filter.the total frequency response of the equalization fir filter and the interpolation filter is given in figure 33- 2 on page 934 . the digital output bitstreams from the sigma-delta modulators should be low- pass filtered to remove high frequency noise inserted by the modulation process. 33.6.6 equalization filter the equalization filter is a simple 3-tap fir filter. the purpose of this filter is to compensate for the pass band frequency response of the sinc interpolation filter. the equalization filter makes the pass band response more flat and moves the -3db corner a little higher. 33.6.7 interpolation filter the interpolation filter interpolates from f s to 128f s . this filter is a 4thorder cascaded integrator- comb filter, and the basic building blocks of this filter is a comb part and an integrator part. 33.6.8 sigma-delta modulator this part is a 3rdorder sigma- delta modulator consisting of thre e differentiators (delta blocks), three integrators (sigma blocks) and a one bit quantizer. the purpose of the integrators is to shape the noise, so that the noise is reduced in the band of interest and increased at the higher frequencies, where it can be filtered.
934 32072d?04/2011 at32uc3a3/a4 33.6.9 frequency response figure 33-2. frequency response, eq-fir+comb 4 0 1 2 3 4 5 6 7 8 9 10 x 10 4 -6 0 -5 0 -4 0 -3 0 -2 0 -1 0 0 10 f req ue nc y [f s] a m p litud e [db ]
935 32072d?04/2011 at32uc3a3/a4 33.7 user interface table 33-2. abdac register memory map offset register register name access reset 0x00 sample data register sdr read/write 0x00000000 0x08 control register cr read/write 0x00000000 0x0c interrupt mask register imr read-only 0x00000000 0x10 interrupt enable register ier write-only 0x00000000 0x14 interrupt disable register idr write-only 0x00000000 0x18 interrupt clear register icr write-only 0x00000000 0x1c interrupt status register isr read-only 0x00000000
936 32072d?04/2011 at32uc3a3/a4 33.7.1 sample data register name: sdr access type: read/write offset: 0x00 reset value: 0x00000000 ? channel1: sample data for channel 1 signed 16-bit sample data for channel 1. ? channel0: signed 16-bit sample data for channel 0 signed 16-bit sample data for channel 0. 31 30 29 28 27 26 25 24 channel1[15:8] 23 22 21 20 19 18 17 16 channel1[7:0] 15 14 13 12 11 10 9 8 channel0[15:8] 76543210 channel0[7:0]
937 32072d?04/2011 at32uc3a3/a4 33.7.2 control register name: cr access type: read/write offset: 0x08 reset value: 0x00000000 ? en: enable audio bitstream dac 1: the module is enabled. 0: the module is disabled. ? swap: swap channels 1: the swap of channel0 and channel1 samples is enabled. 0: the swap of channel0 and channel1 samples is disabled. 31 30 29 28 27 26 25 24 enswap------ 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 --------
938 32072d?04/2011 at32uc3a3/a4 33.7.3 interrupt mask register name: imr access type: read-only offset: 0x0c reset value: 0x00000000 1: the corresponding interrupt is enabled. 0: the corresponding interrupt is disabled. a bit in this register is set when the corresponding bit in ier is written to one. a bit in this register is cleared when the corresponding bit in idr is written to one. 31 30 29 28 27 26 25 24 --txreadyunderrun---- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 --------
939 32072d?04/2011 at32uc3a3/a4 33.7.4 interrupt enable register name: ier access type: write-only offset: 0x10 reset value: 0x00000000 writing a one to a bit in this register will set the corresponding bit in imr. writing a zero to a bit in this register has no effect. 31 30 29 28 27 26 25 24 --txreadyunderrun---- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 --------
940 32072d?04/2011 at32uc3a3/a4 33.7.5 interrupt disable register name: idr access type: write-only offset: 0x14 reset value: 0x00000000 writing a one to a bit in this register will clear the corresponding bit in imr. writing a zero to a bit in this register has no effect. 31 30 29 28 27 26 25 24 --txreadyunderrun---- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 --------
941 32072d?04/2011 at32uc3a3/a4 33.7.6 interrupt clear register name: icr access type: write-only offset: 0x18 reset value: 0x00000000 writing a one to a bit in this register will clear the corresponding bit in isr and the corresponding interrupt request. writing a zero to a bit in this register has no effect. 31 30 29 28 27 26 25 24 --txreadyunderrun---- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 --------
942 32072d?04/2011 at32uc3a3/a4 33.7.7 interrupt status register name: isr access type: read-only offset: 0x1c reset value: 0x00000000 ? txready: tx ready interrupt status this bit is set when the audio bitstream dac is ready to receive a new data in sdr. this bit is cleared when the audio bitstream dac is not ready to receive a new data in sdr. ? underrun: underrun interrupt status this bit is set when at least one audio bitstream dac underrun has occurred since the last time this bit was cleared (by reset or by writing in icr). this bit is cleared when no audio bitstream dac underrun has occurred since the last time this bit was cleared (by reset or by writing in icr). 31 30 29 28 27 26 25 24 --txreadyunderrun---- 23 22 21 20 19 18 17 16 -------- 15 14 13 12 11 10 9 8 -------- 76543210 --------
943 32072d?04/2011 at32uc3a3/a4 34. programming and debugging 34.1 overview general description of programming and debug features, block diagram and introduction of main concepts. 34.2 service access bus the avr32 architecture offers a common interface for access to on-chip debug, programming, and test functions. these are mapped on a common bus called t he service acce ss bus (sab), which is linked to the jtag port through a bus master module, which also handles synchroniza- tion between the debu gger and sab clocks. when accessing the sab through th e debugger ther e are no limitations on debugger frequency compared to chip frequency, although there must be an active system clock in order for the sab accesses to complete. if the system clock is swit ched off in sleep mode, activity on the debugger will restart the system clock automatically, without waking the device from sleep. debuggers may optimize the transfer rate by adjusting the frequency in relation to the system clock. this ratio can be measured with debug protocol specific instructions. the service access bus uses 36 address bits to address memory or registers in any of the slaves on the bus. the bus supports sized accesses of bytes (8 bits), halfwords (16 bits), or words (32 bits). all accesses must be aligned to the size of th e access, i.e. halfword accesses must have the lowest address bit cleared, and word accesses must have the two lowest address bits cleared. 34.2.1 sab address map the service access bus (sab) gives the user access to the internal address space and other features through a 36 bits address space. the 4 msbs identify the slave number, while the 32 lsbs are decoded within the slave?s address space. the sab slaves are shown in table 34-1 on page 943 . 34.2.2 sab security restrictions the service access bus can be restricted by internal security measures. a short description of the security measures are found in the table below. table 34-1. sab slaves, addresses and descriptions. slave address [35:32] description unallocated 0x0 intentionally unallocated ocd 0x1 ocd registers hsb 0x4 hsb memory space, as seen by the cpu hsb 0x5 alternative mapping for hsb space, for compatibility with other 32-bit avr devices. memory service unit 0x6 memory service unit registers reserved other unused
944 32072d?04/2011 at32uc3a3/a4 34.2.2.1 security measure and control location a security measure is a mechanism to either block or a llow sab access to a certain address or address range. a security measure is enabled or disabled by one or several control signals. this is called the control location for the security measure. these security measures can be used to prevent an end user from reading out the code pro- grammed in the flash, for instance. below follows a more in depth description of what locations are accessible when the security measures are active. table 34-2. sab security measures. security measure control location description security bit flashc security bit set programming and debugging not possible, very restricted access. user code programming flashc uprot + security bit set restricts all access except parts of the flash and the flash controller for programming user code. debugging is not possible unless an os running from the secure part of the flash supports it. table 34-3. security bit sab restrictions name address start address end access ocd dccpu, ocd dcemu, ocd dcsr 0x100000110 0x100000118 read/write user page 0x580800000 0x581000000 read other accesses - - blocked table 34-4. user code programming sab restrictions name address start address end access ocd dccpu, ocd dcemu, ocd dcsr 0x100000110 0x100000118 read/write user page 0x580800000 0x581000000 read flashc pb interface 0x5fffe0000 0x5fffe0400 read/write flash pages outside bootprot 0x580000000 + bootprot size 0x580000000 + flash size read/write other accesses - - blocked
945 32072d?04/2011 at32uc3a3/a4 34.3 on-chip debug (ocd) rev: 1.4.2.1 34.3.1 features ? debug interface in compli ance with ieee-isto 5001- 2003 (nexus 2.0) class 2+ ? jtag access to all on-chip debug functions ? advanced program, data, ownership, and watchpoint trace supported ? nanotrace jtag-based trace access ? auxiliary port for high-speed trace information ? hardware support for 6 program and 2 data breakpoints ? unlimited number of softw are breakpoints supported ? automatic crc check of memory regions 34.3.2 overview debugging on the at32uc3a3 is facilitated by a powerful on-chip debug (ocd) system. the user accesses this through an external debug tool which connects to the jtag port and the aux- iliary (aux) port. the aux port is primarily used for trace functi ons, and a jtag-based debugger is sufficient for basic debugging. the debug system is based on the nexus 2.0 standard, class 2+, which includes: ? basic run-time control ? program breakpoints ? data breakpoints ?program trace ? ownership trace ? data trace in addition to the mandatory nexus debug features, the at32uc3a3 implements several useful ocd features, such as: ? debug communication channel between cpu and jtag ? run-time pc monitoring ? crc checking ? nanotrace ? software quality assurance (sqa) support the ocd features are controlled by ocd regist ers, which can be accessed by jtag when the nexus_access jtag instruction is loaded. the cpu can also access ocd registers directly using mtdr/mfdr instructions in any privileged mode. the ocd registers are implemented based on the recommendations in the nexus 2.0 standard, and are detailed in the avr32uc technical reference manual.
946 32072d?04/2011 at32uc3a3/a4 34.3.3 block diagram figure 34-1. on-chip debug block diagram 34.3.4 jtag-based debug features a debugger can control all ocd features by writing ocd registers over the jtag interface. many of these do not depend on output on the aux port, allowing a jtag-based debugger to be used. a jtag-based debugger should connect to the device through a standard 10-pin idc connector as described in the avr32uc technical reference manual. on-chip debug jtag debug pc debug instruction cpu breakpoints program trace data trace ownership trace watchpoints transmit queue aux jtag internal sram s e r v i c e a c c e s s b u s memory service unit hsb bus matrix memories and peripherals
947 32072d?04/2011 at32uc3a3/a4 figure 34-2. jtag-based debugger 34.3.4.1 debug communication channel the debug communication channel (d cc) consists of a pair ocd registers with associated handshake logic, accessible to both cpu an d jtag. the registers can be used to exchange data between the cpu and the jtag master, both runtime as well as in debug mode. 34.3.4.2 breakpoints one of the most fundamental debug features is the abilit y to halt the cpu, to examine registers and the state of the system. this is accomplish ed by breakpoints, of which many types are available: ? unconditional breakpoints are set by writing ocd registers by jtag, halting the cpu immediately. ? program breakpoints halt the cpu when a specific address in the program is executed. ? data breakpoints halt the cpu when a specific memory address is read or written, allowing variables to be watched. ? software breakpoints halt the cpu when the breakpoint instruction is executed. when a breakpoint triggers, the cpu enters debug mode, and the d bit in the status register is set. this is a privileged mode with dedicated return address and return status registers. all privi- leged instructions are permitted. debug mode can be entered as either ocd mode, running instructions from jtag, or monitor mode, running instructions from program memory. avr32 jtag-based debug tool pc jtag 10-pin idc
948 32072d?04/2011 at32uc3a3/a4 34.3.4.3 ocd mode when a breakpoint triggers, the cpu enters ocd mode, and instructions are fetched from the debug instruction ocd register. each time this register is written by jtag, the instruction is executed, allowing the jtag to execute cpu instructions directly. the jtag master can e.g. read out the register file by issuing mtdr instructions to the cpu, writing each register to the debug communication channel ocd registers. 34.3.4.4 monitor mode since the ocd registers are directly accessible by the cpu, it is possible to build a software- based debugger that runs on the cpu itself. setting the monitor mode bit in the development control register causes the cpu to enter monitor mode instead of ocd mode when a breakpoint triggers. monitor mode is similar to ocd mode, except that instructions are fetched from the debug exception vector in regular program memory, instead of issued by jtag. 34.3.4.5 program counter monitoring normally, the cpu would need to be halted for a jtag-based debugger to examine the current pc value. however, the at32uc3a3 provides a debug program counter ocd register, where the debugger can continuously read the current pc without affecting the cpu. this allows the debugger to generate a simple statistic of the time spent in various areas of the code, easing code optimization. 34.3.5 memory service unit the memory service unit (msu) is a block dedicated to test and debug functionality. it is con- trolled through a dedicated set of registers addressed through the memory_service jtag command. 34.3.5.1 cyclic redundancy check (crc) the msu can be used to automatically calculate the crc of a block of data in memory. the ocd will then read out each word in the specified memory bloc k and report the crc32-value in an ocd register. 34.3.5.2 nanotrace the msu additionally supports nanotrace. this is an avr32-specific feature, in which trace data is output to memory instead of the aux port . this allows the trace data to be extracted by jtag memory_access, enabling trace features for jtag-based debuggers. the user must write msu registers to configure the address and size of the memory block to be used for nano- trace. the nanotrace buffer can be anywhere in th e physical address range, including internal and external ram, through an ebi, if present. th is area may not be used by the application run- ning on the cpu. 34.3.6 aux-based debug features utilizing the auxiliary (aux) port gives a ccess to a wide range of advanced debug features. of prime importance are the trace features, which allow an external debugger to receive continuous information on the program execution in the cpu. additionally, event in and event out pins allow external events to be correlated with the program flow. the aux port contains a number of pins, as shown in table 34-5 on page 949 . these are multi- plexed with i/o controller lines, and must exp licitly be enabled by writing ocd registers before the debug session starts. the aux port is mapped to two different locations, selectable by ocd registers, minimizing the chance that the aux port w ill need to be shared with an application.
949 32072d?04/2011 at32uc3a3/a4 debug tools utilizing the aux port should connec t to the device throug h a nexus-compliant mic- tor-38 connector, as described in the avr32uc technical reference manual. this connector includes the jtag signals and the reset_n pin, giving full access to the programming and debug features in the device. figure 34-3. aux+jtag based debugger 34.3.6.1 trace operation trace features are enabled by writing ocd registers by jtag. the ocd extracts the trace infor- mation from the cpu, compresses this information and formats it into variable-length messages according to the nexus standard. the messages are buffered in a 16-frame transmit queue, and are output on the aux port one frame at a time. table 34-5. auxiliary port signals signal direction description mcko output trace data output clock mdo[5:0] output trace data output mseo[1:0] output trace frame control evti_n input event in evto_n output event out avr32 aux+jtag debug tool jtag aux high speed mictor38 trace buffer pc
950 32072d?04/2011 at32uc3a3/a4 the trace features can be configured to be very selective, to reduce the bandwidth on the aux port. in case the transmit queue overflows, er ror messages are produced to indicate loss of data. the transmit queue module can optionally be configured to halt the cpu when an overflow occurs, to prevent the loss of messages, at the expense of longer run-time for the program. 34.3.6.2 program trace program trace allows the debugger to continuously monitor the program execution in the cpu. program trace messages are generated for every branch in the program, and contains com- pressed information, which allows the debugger to correlate the message with the source code to identify the branch instruction and target address. 34.3.6.3 data trace data trace outputs a message every time a specific location is read or written. the message contains information about the type (read/write) and size of the access, as well as the address and data of the accessed location. the at32uc3a3 contains two data trace channels, each of which are controlled by a pair of ocd registers which determine the range of addresses (or sin- gle address) which should produce data trace messages. 34.3.6.4 ownership trace program and data trace operate on virtual addresses. in cases where an operating system runs several processes in overlapping virtual memory segments, the ownership trace feature can be used to identify th e process switch. when the o/s activates a process, it will write the process id number to an ocd register, which produces an ownership trace message, allowing the debug- ger to switch context for the subsequent progra m and data trace messages. as the use of this feature depends on the software running on the cpu, it can also be used to extract other types of information from the system. 34.3.6.5 watchpoint messages the breakpoint modules normally used to generate program and data breakpoints can also be used to generate watchpoint messages, allowing a debugger to monitor program and data events without halting the cpu. watchpoints can be enabled independently of breakpoints, so a breakpoint module can optionally halt the cpu w hen the trigger condition occurs. data trace modules can also be configured to produce watc hpoint messages instead of regular data trace messages. 34.3.6.6 event in and event out pins the aux port also contains an event in pin (evti_n) and an event out pin (evto_n). evti_n can be used to trigger a breakpoint when an external event occurs. it can also be used to trigger specific program and data trace synchronization messages, allowing an external event to be correlated to the program flow. when the cpu enters debug mode, a debug status message is transmitted on the trace port. all trace messages can be timestamped when they are received by the debug tool. however, due to the latency of the trans mit queue buffering, the timest amp will not be 100% accurate. to improve this, evto_n can toggle every time a message is inserted into the transmit queue, allowing trace messages to be timestamped prec isely. evto_n can also toggle when a break- point module triggers, or when the cpu enters debug mode, for any reason. this can be used to measure precisely when the respective internal event occurs.
951 32072d?04/2011 at32uc3a3/a4 34.3.6.7 software quality analysis (sqa) software quality analysis (sqa) deals with two important issues regarding embedded software development. code coverage involves identifying untested parts of the embedded code, to improve test procedures and thus the quality of the released software. performance analysis allows the developer to precisely quantify the time spent in various parts of the code, allowing bottlenecks to be identified and optimized. program trace must be used to accomplish these tasks without instrumenting (altering) the code to be examined. however, traditional program trace cannot reconstruct the current pc value without correlating the trace information with the source code, which cannot be done on-the-fly. this limits program trace to a relatively short time segment, determined by the size of the trace buffer in the debug tool. the ocd system in at32uc3a3 ex tends program trace with sq a capabilities, allowing the debug tool to reconstruct the pc value on-the-f ly. code coverage and performance analysis can thus be reported for an unlimited execution sequence.
952 32072d?04/2011 at32uc3a3/a4 34.4 jtag and boundary-scan (jtag) rev: 2.0.0.4 34.4.1 features ? ieee1149.1 compli ant jtag interface ? boundary-scan chain fo r board-level testing ? direct memory access and programming capabilities through jtag interface 34.4.2 overview the jtag interface offers a four pin programming and debug solution, including boundary-scan support for board-level testing. figure 34-4 on page 953 shows how the jtag is connected in an 32-bit avr device. the tap controller is a state machine controlled by the tck and tms signals. the tap controller selects either the jtag instruction register or one of several data registers as the scan chain (shift register) between the tdi-input and tdo-output. the instruction register holds jt ag instructions controlling the be havior of a data register. the device identification register, bypass register , and the boundary-scan chain are the data reg- isters used for board-level testing. the reset register can be used to keep the device reset during test or programming. the service access bus (sab) interface cont ains address and data registers for the service access bus, which gives access to on-chip debug, programming, and other functions in the device. the sab offers se veral modes of access to the addr ess and data regist ers, as described in section 34.4.10 . section 34.5 lists the supported jtag instructions, wit h references to the description in this document.
953 32072d?04/2011 at32uc3a3/a4 34.4.3 block diagram figure 34-4. jtag and boundary-scan access 34.4.4 i/o lines description 34.4.5 product dependencies in order to use this module, other parts of the system must be configured correctly, as described below. table 34-6. i/o line description pin name pin description type active level tck test clock input. fully asynchronous to system clock frequency. input tms test mode select, sampled on rising tck. input tdi test data in, sampled on rising tck. input tdo test data out, driven on falling tck. output 32-bit avr device jtag data registers tap controller instruction register device identification register by-pass register reset register service access bus interface boundary scan chain pins and analog blocks data register scan enable jtag pins boundary scan enable 2nd jtag device jtag master tdi tdo part specific registers ... tdo tdi tms tms tck tck instruction register scan enable sab internal i/o lines jtag tms tdi tdo tck
954 32072d?04/2011 at32uc3a3/a4 34.4.5.1 power management when an instruction that accesses the sab is loaded in the instruction register, before entering a sleep mode, the system clocks are not switched off to a llow debugging in sleep modes. this can lead to a program behaving differently when debugging. 34.4.5.2 clocks the jtag interface uses the external tck pin as clock source. this clock must be provided by the jtag master. instructions that use the sab bus requires the internal main clock to be running. 34.4.6 jtag interface the jtag interface is accessed through the dedicated jtag pins shown in table 34-6 on page 953 . the tms control line navigates the tap controller, as shown in figure 34-5 on page 955 . the tap controller manages the serial access to the jtag instruction and data registers. data is scanned into the selected instruction or data register on tdi, and out of the register on tdo, in the shift-ir and shift-dr states, respectively. th e lsb is shifted in and out first. tdo is high- z in other states than shift-ir and shift-dr. the device implements a 5-bit instruction regist er (ir). a number of public jtag instructions defined by the jtag standard are supported, as described in section 34.5.2 , as well as a num- ber of 32-bit avr-specific private jtag instructions described in section 34.5.3 . each instruction selects a specific data register for the shift-dr path, as described for each instruction.
955 32072d?04/2011 at32uc3a3/a4 figure 34-5. tap controller state diagram test-logic- reset run-test/ idle select-dr scan select-ir scan capture-dr capture-ir shift-dr shift-ir exit1-dr exit1-ir pause-dr pause-ir exit2-dr exit2-ir update-dr update-ir 0 1 1 1 0 0 1 0 1 1 0 0 1 0 1 1 1 0 1 1 0 0 1 1 0 1 0 0 0 0 0 1
956 32072d?04/2011 at32uc3a3/a4 34.4.7 how to initialize the module independent of the initial state of the tap controller, the test-logic-reset state can always be entered by holding tms high for 5 tck clock periods. this sequence should always be applied at the start of a jtag session to bring the tap controller into a defined state before applying jtag commands. applying a 0 on tms for 1 tck period brings the tap controller to the run- test/idle state, which is the starting point for jtag operations. 34.4.8 typical sequence assuming run-test/idle is the present state, a typical scenario for using the jtag interface follows. 34.4.8.1 scanning in jtag instruction at the tms input, apply the sequence 1, 1, 0, 0 at the rising edges of tck to enter the shift instruction register (shift-ir) state. while in this state, shift the 5 bits of the jtag instructions into the jtag instruction register from the tdi input at the rising edge of tck. during shifting, the jtag outputs status bits on tdo, refer to section 34.5 for a description of these. the tms input must be held low during input of the 4 lsbs in order to remain in the shift-ir state. the jtag instruction selects a particular data register as path between tdi and tdo and controls the circuitry surrounding th e selected data register. apply the tms sequence 1, 1, 0 to re-enter the run-test/idle state. the instruction is latched onto the parallel output from the shift register path in the update-ir state. the exit-ir, pause-ir, and exit2-ir states are only used for navigating the state machine. figure 34-6. scanning in jtag instruction 34.4.8.2 scanning in/out data at the tms input, apply the sequence 1, 0, 0 at the rising edges of tck to enter the shift data register (shift-dr) state. while in this state, upload the selected data register (selected by the present jtag instruction in the jtag instruction register) from the tdi input at the rising edge of tck. in order to remain in the shift-dr state, the tms input must be held low. while the data register is shifted in from the tdi pin, the parallel inputs to the data register captured in the capture-dr state is shifted out on the tdo pin. tck tap state tlr rti seldr selir capir shir ex1ir updir rti tms tdi instruction tdo impldefined
957 32072d?04/2011 at32uc3a3/a4 apply the tms sequence 1, 1, 0 to re-enter the run-test/idle state. if the selected data register has a latched parallel-output, the latching takes place in the update-dr state. the exit-dr, pause-dr, and exit2-dr states are only used for navigating the state machine. as shown in the state diagram, the run-test/idle state need not be entered between selecting jtag instruction and using data registers. 34.4.9 boundary-scan the boundary-scan chain has the c apability of driving an d observing the logic levels on the digi- tal i/o pins, as well as the boundary between digi tal and analog logic for analog circuitry having off-chip connections. at system level, all ics having jtag capabilities ar e connected serially by the tdi/tdo signals to form a long shift register. an external controller sets up the devices to drive values at their output pins, and observe the input values received from other devices. the controller compares the received data with the expected result. in this way, boundary-scan pro- vides a mechanism for testing interconnections and integrity of components on printed circuits boards by using the 4 tap signals only. the four ieee 1149.1 defined mandatory jtag in structions idcode, bypass, sample/pre- load, and extest can be used for testing the printed circuit board. initial scanning of the data register path will show th e id-code of the device, sinc e idcode is the default jtag instruction. it may be desirable to have the 32-bit avr device in reset during test mode. if not reset, inputs to the device may be determined by the scan operations, and the internal software may be in an undetermi ned state when exiting the test mode. if nee ded, the bypass instruction can be issued to make the shortest possible scan chain through the device. the device can be set in the reset state either by pulling the external resetn pi n low, or issuing the avr_reset instruction with appropriate setting of the reset data register. the extest instruction is used for sampling external pins and loading output pins with data. the data from the output latch will be driven out on the pins as soon as the extest instruction is loaded into the jtag ir-register. therefore, the sample/preload should also be used for setting initial values to the scan ring, to avoid damaging the board when issuing the extest instruction for the first time. sample/preload c an also be used for taking a snapshot of the external pins during normal operation of the part. when using the jtag interface for boundary-scan, the jtag tck clock is independent of the internal chip clock. the internal chip clock is not required to run during boundary-scan operations. note: for pins connected to 5v lines care should be taken to not drive the pins to a logic one using boundary-scan, as this will create a current fl owing from the 3,3v driver to the 5v pull-up on the line. optionally a series resistor can be added between the line and the pin to reduce the current. details about the boundary-scan chain can be found in the bsdl file for the device. this can be found on the atmel website. 34.4.10 service access bus the avr32 architecture offers a common interface for access to on-chip debug, programming, and test functions. these are mapped on a common bus called t he service acce ss bus (sab), which is linked to the jtag through a bus master module, which also handles synchronization between the tck and sab clocks.
958 32072d?04/2011 at32uc3a3/a4 for more information about the sab and a list of sab slaves see the service access bus chapter. 34.4.10.1 sab address mode the memory_sized_access instruction allows a sized read or write to any 36-bit address on the bus. memory_word_access is a shorthand instruction for 32-bit accesses to any 36-bit address, while the nexus_access instruct ion is a nexus-compliant shorthand instruc- tion for accessing the 32-bit ocd registers in the 7-bit address space reserved for these. these instructions require two passes through the shift-dr tap state: one for the address and control information, and one for data. 34.4.10.2 block transfer to increase the transfer rate, consecutive me mory accesses can be accomplished by the memory_block_access instruction, which only r equires a single pass through shift-dr for data transfer only. the address is automatically incremented according to the size of the last sab transfer. 34.4.10.3 canceling a sab access it is possible to abort an ongoing sab access by the cancel_access instruction, to avoid hanging the bus due to an extremely slow slave. 34.4.10.4 busy reporting as the time taken to perform an access may vary depending on system activity and current chip frequency, all the sab access jtag instructions can return a busy indicator. this indicates whether a delay needs to be inserted, or an operation needs to be repeated in order to be suc- cessful. if a new acce ss is requested while the sab is busy, the request is ignored. the sab becomes busy when: ? entering update-dr in the address phase of any read operation, e.g., after scanning in a nexus_access address wit h the read bit set. ? entering update-dr in the data phase of any write operation, e.g., after scanning in data for a nexus_access write. ? entering update-dr during a memory_block_access. ? entering update-dr after scanning in a counter value for sync. ? entering update-ir af ter scanning in a memory_block _access if the previous access was a read and data was scanned after scanning the address. the sab becomes ready again when: ? a read or write operation completes. ? a sync countdown completed. ? a operation is cancelled by the cancel_access instruction. what to do if the busy bit is set: ? during shift-ir: the new instruction is selected, but the previous operation has not yet completed and will continue (u nless the new instruction is cancel_access). you may continue shifting the same instruction until the busy bit clears, or start shifting data. if shifting data, you must be prepared that the data shift may also report busy. ? during shift-dr of an address: the new address is ignored. the sab stays in address mode, so no data must be shifted. repeat the address until the busy bit clears.
959 32072d?04/2011 at32uc3a3/a4 ? during shift-dr of read data: the read data is invalid. the sab stays in data mode. repeat scanning until the busy bit clears. ? during shift-dr of write data: the write data is ignored. the sab stays in data mode. repeat scanning until the busy bit clears. 34.4.10.5 error reporting the service access bus may not be able to comp lete all accesses as requested. this may be because the address is invalid, the addressed area is read-only or cannot handle byte/halfword accesses, or because the chip is set in a protected mode where only limited accesses are allowed. the error bit is updated when an access complete s, and is cleared when a new access starts. what to do if the error bit is set: ? during shift-ir: the new instruction is selected. the last operation performed using the old instruction did not complete successfully. ? during shift-dr of an address: the previous operation failed. the new address is accepted. if the read bit is set, a read operation is started. ? during shift-dr of read data: the read operation failed, and the read data is invalid. ? during shift-dr of write data: the previous write operation failed. the new data is accepted and a write operation started. this should only occur during block writes or stream writes. no error can occur between scanning a write address and the following write data. ? while polling with cancel_access: the previous access was cancelled. it may or may not have actually completed. ? after power-up: the error bit is set after power up, but there has been no previous sab instruction so this error can be discarded. 34.4.10.6 protected reporting a protected status may be reported during shift-ir or shift-dr. this indicates that the security bit in the flash controller is set and that the chip is locked for access, according to section 34.5.1 . the protected state is reported when: ? the flash controller is under reset. this can be due to the avr_reset command or the reset_n line. ? the flash controller has not read the security bit from the flash yet (this will take a a few ms). happens after the flash controller reset has been released. ? the security bit in the flash controller is set. what to do if the protected bit is set: ? release all active avr_ reset domains, if any. ? release the reset_n line. ? wait a few ms for the security bit to clear. it can be set temporarily due to a reset. ? perform a chip_erase to clear the security bit. note : this will erase all the contents of the non-volatile memory.
960 32072d?04/2011 at32uc3a3/a4 34.5 jtag instruction summary the implemented jtag instructions in the 32-bit avr are shown in the table below. 34.5.1 security restrictions when the security fuse in the flash is programmed, the following jtag instructions are restricted: ? nexus_access ? memory_word_access ? memory_block_access ? memory_sized_access for description of what memory locations remain accessible, please refer to the sab address map. full access to these instructions is re-enabled when the security fuse is erased by the chip_erase jtag instruction. note that the security bit will read as programmed and block these instructions also if the flash controller is statically reset. table 34-7. jtag instruction summary instruction opcode instruction description 0x01 idcode select the 32-bit device ident ification register as data register. 0x02 sample_preload take a snapshot of external pin values without affe cting system operation. 0x03 extest select boundary-scan chain as data register for testing circuitry external to the device. 0x04 intest select boundary-scan chain for internal testing of the device. 0x06 clamp bypass device through bypass register, while driving outputs from boundary- scan register. 0x0c avr_reset apply or remove a static reset to the device 0x0f chip_erase erase the device 0x10 nexus_access select the sab address and data regist ers as data register for the tap. the registers are accessed in nexus mode. 0x11 memory_word_access select the sab address an d data registers as data register for the tap. 0x12 memory_block_access select the sab data register as data register for the tap. the address is auto-incremented. 0x13 cancel_access cancel an ongoing nexus or memory access. 0x14 memory_service select the sab address and data regist ers as data register for the tap. the registers are accessed in memory service mode. 0x15 memory_sized_access select the sab address an d data registers as data register for the tap. 0x17 sync synchronization counter 0x1c halt halt the cpu for safe programming. 0x1f bypass bypass this device through the bypass register. others n/a acts as bypass
961 32072d?04/2011 at32uc3a3/a4 other security mechanisms can also restrict these functions. if such mechanisms are present they are listed in the sab address map section. 34.5.1.1 notation table 34-9 on page 961 shows bit patterns to be shifted in a format like " peb01 ". each character corresponds to one bit, and eight bits are grouped together for re adability. the least significant- bit is always shifted first, and the most signific ant bit shifted last. the symbols used are shown in table 34-8 . in many cases, it is not required to shift all bits through the data register. bit patterns are shown using the full width of the shift register, but the suggested or required bits are emphasized using bold text. i.e. given the pattern " aaaaaaar xxxxxxxx xxxxxxxx xxxxxxxx xx", the shift register is 34 bits, but the test or debug unit may choose to shift only 8 bits " aaaaaaar ". the following describes how to interpret the fields in the instruction description tables: table 34-8. symbol description symbol description 0 constant low value - always reads as zero. 1 constant high value - always reads as one. a an address bit - always scanned with the least significant bit first b a busy bit. reads as one if the sab was busy, or zero if it was not. see section 34.4.10.4 for details on how the busy reporting works. d a data bit - always scanned with the least significant bit first. e an error bit. reads as one if an error occurred, or zero if not. see section 34.4.10.5 for details on how the error reporting works. p the chip protected bit. some devices may be se t in a protected state where access to chip internals are severely restricted. see the docum entation for the specific device for details. on devices without this possibility, this bit always reads as zero. r a direction bit. set to one to request a read, set to zero to request a write. s a size bit. the size encoding is described where used. x a don?t care bit. any value can be shifted in, and output data should be ignored. table 34-9. instruction description instruction description ir input value shows the bit pattern to shift into ir in t he shift-ir state in order to select this instruction. the pattern is show both in binary and in hexadecimal form for convenience. example: 10000 (0x10) ir output value shows the bit pattern shifted out of ir in t he shift-ir state when this instruction is active. example: peb01
962 32072d?04/2011 at32uc3a3/a4 34.5.2 public jtag instructions the jtag standard defines a number of public jtag instructions. these instructions are described in the sections below. 34.5.2.1 idcode this instruction selects the 32 bit device identification register (did) as data register. the did register consists of a version number, a device number, and the manufacturer code chosen by jedec. this is the default instruction after a jtag reset. details about the did register can be found in the module configuration section at the end of this chapter. starting in run-test/idle, the device identification register is accessed in the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. return to run-test/idle. 5. select the dr scan path. 6. in capture-dr: the idcode value is latched into the shift register. 7. in shift-dr: the idcode scan ch ain is shifted by the tck input. 8. return to run-test/idle. 34.5.2.2 sample_preload this instruction takes a snap-shot of the input/ output pins without affect ing the system operation, and pre-loading the scan chain without updating the dr-latch. the boundary-scan chain is selected as data register. starting in run-test/idle, the device identification register is accessed in the following way: dr size shows the number of bits in the data register chain when this instruction is active. example: 34 bits dr input value shows which bit pattern to shift into the data register in the shift-dr state when this instruction is active. multiple such line s may exist, e.g., to distinguish between reads and writes. example: aaaaaaar xxxxxxxx xxxxxxxx xxxxxxxx xx dr output value shows the bit pattern shifted out of the dat a register in the sh ift-dr state when this instruction is active. multiple such line s may exist, e.g., to distinguish between reads and writes. example: xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb table 34-9. instruction description (continued) instruction description table 34-10. idcode details instructions details ir input value 00001 (0x01) ir output value p0001 dr size 32 dr input value xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx dr output value device identification register
963 32072d?04/2011 at32uc3a3/a4 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. return to run-test/idle. 5. select the dr scan path. 6. in capture-dr: the data on the external pins are sampled into the boundary-scan chain. 7. in shift-dr: the boundary-scan chain is shifted by the tck input. 8. return to run-test/idle. 34.5.2.3 extest this instruction selects the boundary-scan chain as data register for testing circuitry external to the 32-bit avr package. the contents of the latched outputs of the boundary-scan chain is driven out as soon as the jtag ir-register is loaded with the extest instruction. starting in run-test/idle, the extest instruction is accessed the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. in update-ir: the data from the boundary-scan chain is applied to the output pins. 5. return to run-test/idle. 6. select the dr scan path. 7. in capture-dr: the data on the external pins is sampled into the boundary-scan chain. 8. in shift-dr: the boundary-scan chain is shifted by the tck input. 9. in update-dr: the data from the scan chain is applied to the output pins. 10. return to run-test/idle. table 34-11. sample_preload details instructions details ir input value 00010 (0x02) ir output value p0001 dr size depending on boundary-scan chain, see bsdl-file. dr input value depending on boundary-scan chain, see bsdl-file. dr output value depending on boundary-scan chain, see bsdl-file. table 34-12. extest details instructions details ir input value 00011 (0x03) ir output value p0001 dr size depending on boundary-scan chain, see bsdl-file. dr input value depending on boundary-scan chain, see bsdl-file. dr output value depending on boundary-scan chain, see bsdl-file.
964 32072d?04/2011 at32uc3a3/a4 34.5.2.4 intest this instruction selects the boundary-scan chain as data register for testing internal logic in the device. the logic inputs are determined by the boundary-scan chain, and the logic outputs are captured by the boundary-scan chain. the device output pins are driven from the boundary-scan chain. starting in run-test/idle, the intest instruction is access ed the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. in update-ir: the data from the boundary-scan chain is applied to the internal logic inputs. 5. return to run-test/idle. 6. select the dr scan path. 7. in capture-dr: the data on the internal logic is sampled into the boundary-scan chain. 8. in shift-dr: the boundary-scan chain is shifted by the tck input. 9. in update-dr: the data from the boundary-scan chain is applied to internal logic inputs. 10. return to run-test/idle. 34.5.2.5 clamp this instruction selects the bypass register as data register. the device output pins are driven from the boundary-scan chain. starting in run-test/idle, the clamp instruction is acce ssed the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. in update-ir: the data from the boundary-scan chain is applied to the output pins. 5. return to run-test/idle. 6. select the dr scan path. 7. in capture-dr: a logic ?0? is loaded into the bypass register. 8. in shift-dr: data is scanned from tdi to tdo through the bypass register. table 34-13. intest details instructions details ir input value 00100 (0x04) ir output value p0001 dr size depending on boundary-scan chain, see bsdl-file. dr input value depending on boundary-scan chain, see bsdl-file. dr output value depending on boundary-scan chain, see bsdl-file.
965 32072d?04/2011 at32uc3a3/a4 9. return to run-test/idle. 34.5.2.6 bypass this instruction selects the 1-bit bypass register as data register. starting in run-test/idle, the clamp instruction is acce ssed the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. return to run-test/idle. 5. select the dr scan path. 6. in capture-dr: a logic ?0? is loaded into the bypass register. 7. in shift-dr: data is scanned from tdi to tdo through the bypass register. 8. return to run-test/idle. 34.5.3 private jtag instructions the 32-bit avr defines a number of private jt ag instructions, not defined by the jtag stan- dard. each instruction is br iefly described in text, with det ails following in table form. 34.5.3.1 nexus_access this instruction allows nexus-compliant access to the on-chip debug registers through the sab. the 7-bit register index, a read/write co ntrol bit, and the 32-bit data is accessed through the jtag port. the data register is alternately interpreted by the sab as an address register and a data regis- ter. the sab starts in addre ss mode after the nexus_access instruction is selected, and toggles between address and data mode each time a data scan completes with the busy bit cleared. note : the polarity of the direction bit is inverse of the nexus standard. table 34-14. clamp details instructions details ir input value 00110 (0x06) ir output value p0001 dr size 1 dr input value x dr output value x table 34-15. bypass details instructions details ir input value 11111 (0x1f) ir output value p0001 dr size 1 dr input value x dr output value x
966 32072d?04/2011 at32uc3a3/a4 starting in run-test/idle, ocd registers are accessed in the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. return to run-test/idle. 5. select the dr scan path. 6. in shift-dr: scan in the direction bit (1=read, 0=write) and the 7-bit address for the ocd register. 7. go to update-dr and re-enter select-dr scan. 8. in shift-dr: for a read operation, scan out the contents of the addressed register. for a write operation, scan in the new contents of the register. 9. return to run-test/idle. for any operation, the full 7 bits of the address must be provided. for write operations, 32 data bits must be provided, or the result will be undefined. for read ope rations, shifting may be termi- nated once the required number of bits have been acquired. 34.5.3.2 memory_service this instruction allows access to registers in an optional memory service unit. the 7-bit register index, a read/write control bit, and the 32-bit data is accessed through the jtag port. the data register is alternately interpreted by the sab as an address register and a data regis- ter. the sab starts in addres s mode after the memory_service instruction is selected, and toggles between address and data mode each time a data scan completes with the busy bit cleared. starting in run-test/idle, memory service registers are accessed in the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. return to run-test/idle. 5. select the dr scan path. 6. in shift-dr: scan in the direction bit (1=read, 0=write) and the 7-bit address for the memory service register. table 34-16. nexus_access details instructions details ir input value 10000 (0x10) ir output value peb01 dr size 34 bits dr input value (address phase) aaaaaaar xxxxxxxx xxxxxxxx xxxxxxxx xx dr input value (data read phase) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xx dr input value (data write phase) dddddddd dddddddd dddddddd dddddddd xx dr output value (address phase) xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb dr output value (data read phase) eb dddddddd dddddddd dddddddd dddddddd dr output value (data write phase) xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb
967 32072d?04/2011 at32uc3a3/a4 7. go to update-dr and re-enter select-dr scan. 8. in shift-dr: for a read operation, scan out the contents of the addressed register. for a write operation, scan in the new contents of the register. 9. return to run-test/idle. for any operation, the full 7 bits of the address must be provided. for write operations, 32 data bits must be provided, or the result will be undefined. for read ope rations, shifting may be termi- nated once the required number of bits have been acquired. 34.5.3.3 memory_sized_access this instruction allows access to the entire service access bus data area. data is accessed through a 36-bit byte index, a 2-bit size, a direction bit, and 8, 16, or 32 bits of data. not all units mapped on the sab bus may support all sizes of accesses, e.g., some may only support word accesses. the data register is alternately interpreted by the sab as an address register and a data regis- ter. the sab starts in address mode after the memory_sized_access instruction is selected, and toggles between address and data mode each time a data scan completes with the busy bit cleared. table 34-17. memory_service details instructions details ir input value 10100 (0x14) ir output value peb01 dr size 34 bits dr input value (address phase) aaaaaaar xxxxxxxx xxxxxxxx xxxxxxxx xx dr input value (data read phase) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xx dr input value (data write phase) dddddddd dddddddd dddddddd dddddddd xx dr output value (address phase) xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb dr output value (data read phase) eb dddddddd dddddddd dddddddd dddddddd dr output value (data write phase) xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb
968 32072d?04/2011 at32uc3a3/a4 the size field is encoded as i table 34-18 . starting in run-test/idle, sab data is accessed in the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. return to run-test/idle. 5. select the dr scan path. 6. in shift-dr: scan in the direction bit (1=read, 0=write), 2-bit access size, and the 36-bit address of the data to access. 7. go to update-dr and re-enter select-dr scan. 8. in shift-dr: for a read operation, scan out the contents of the addressed area. for a write operation, scan in the new contents of the area. 9. return to run-test/idle. for any operation, the full 36 bits of the address must be provided. for write operations, 32 data bits must be provided, or the result will be undefined. for read ope rations, shifting may be termi- nated once the required number of bits have been acquired. table 34-18. size field semantics size field value access size data alignment 00 byte (8 bits) address modulo 4 : data alignment 0: dddddddd xxxxxxxx xxxxxxxx xxxxxxxx 1: xxxxxxxx dddddddd xxxxxxxx xxxxxxxx 2: xxxxxxxx xxxxxxxx dddddddd xxxxxxxx 3: xxxxxxxx xxxxxxxx xxxxxxxx dddddddd 01 halfword (16 bits) address modulo 4 : data alignment 0: dddddddd dddddddd xxxxxxxx xxxxxxxx 1: not allowed 2: xxxxxxxx xxxxxxxx dddddddd dddddddd 3: not allowed 10 word (32 bits) address modulo 4 : data alignment 0: dddddddd dddddddd dddddddd dddddddd 1: not allowed 2: not allowed 3: not allowed 11 reserved n/a table 34-19. memory_sized_access details instructions details ir input value 10101 (0x15) ir output value peb01 dr size 39 bits dr input value (address phase) aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaassr dr input value (data read phase) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxx dr input value (data write phase) dddddddd dddddddd dddddddd dddddddd xxxxxxx
969 32072d?04/2011 at32uc3a3/a4 34.5.3.4 memory_word_access this instruction allows access to the entire service access bus data area. data is accessed through the 34 msb of the sab addr ess, a direction bit, and 32 bits of data. this instruction is identical to memory_sized_access except that it always does word sized accesses. the size field is implied, and the two lowest address bits are removed and not scanned in . note: this instruction was previously known as memory_access, and is provided for back- wards compatibility. the data register is alternately interpreted by the sab as an address register and a data regis- ter. the sab starts in address mode after the memory_word_access instruction is selected, and toggles between address and data mode each time a data scan completes with the busy bit cleared. starting in run-test/idle, sab data is accessed in the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. return to run-test/idle. 5. select the dr scan path. 6. in shift-dr: scan in the direction bit (1=read, 0=write) and the 34-bit address of the data to access. 7. go to update-dr and re-enter select-dr scan. 8. in shift-dr: for a read operation, scan out the contents of the addressed area. for a write operation, scan in the new contents of the area. 9. return to run-test/idle. for any operation, the full 34 bits of the address must be provided. for write operations, 32 data bits must be provided, or the result will be undefined. for read ope rations, shifting may be termi- nated once the required number of bits have been acquired. dr output value (address phase) xxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb dr output value (dat a read phase) xxxxxeb dddddddd dddddddd dddddddd dddddddd dr output value (d ata write phase) xxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb table 34-19. memory_sized_access details (continued) instructions details table 34-20. memory_word_access details instructions details ir input value 10001 (0x11) ir output value peb01 dr size 35 bits dr input value (address phase) aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aar dr input value (data read phase) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxx dr input value (data write phase) dddddddd dddddddd dddddddd dddddddd xxx
970 32072d?04/2011 at32uc3a3/a4 34.5.3.5 memory_block_access this instruction allows ac cess to the entire sab data area. up to 32 bits of data is accessed at a time, while the address is sequentially incr emented from the previously used address. in this mode, the sab a ddress, size, and access direction is not provided with each access. instead, the previous address is auto-incremente d depending on the specified size and the pre- vious operation repeated. the address must be set up in advance with memory_size_access or memory_word_acce ss. it is allowed, but not required, to shift data after shifting the address. this instruction is primarily intended to speed up large quantities of sequential word accesses. it is possible to use it also for byte and halfword accesses, but the overhead in this is case much larger as 32 bits must still be shifted for each access. the following sequence should be used: 1. use the memory_size_access or memory_word_access to read or write the first location. 2. return to run-test/idle. 3. select the ir scan path. 4. in capture-ir: the ir output value is latched into the shift register. 5. in shift-ir: the instruction register is shifted by the tck input. 6. return to run-test/idle. 7. select the dr scan path. t he address will now have increment ed by 1, 2, or 4 (corre- sponding to the next byte, halfword, or word location). 8. in shift-dr: for a read operation, scan out the contents of the next addressed location. for a write operation, scan in the new contents of the next addressed location. 9. go to update-dr. 10. if the block access is not complete, return to select-dr scan and repeat the access. 11. if the block access is complete, return to run-test/idle. for write operations, 32 data bits must be pr ovided, or the result will be undefined. for read operations, shifting may be terminated once the required number of bits have been acquired. dr output value (address phase) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xeb dr output value (data read phase) xeb dddddddd dddddddd dddddddd dddddddd dr output value (d ata write phase) xxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb table 34-20. memory_word_access details (continued) instructions details table 34-21. memory_block_access details instructions details ir input value 10010 (0x12) ir output value peb01 dr size 34 bits dr input value (data read phase) xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xx
971 32072d?04/2011 at32uc3a3/a4 the overhead using block word access is 4 cycles per 32 bits of data, resulting in an 88% trans- fer efficiency, or 2.1 mbytes per second with a 20 mhz tck frequency. 34.5.3.6 cancel_access if a very slow memory location is accessed du ring a sab memory access, it could take a very long time until the busy bit is cleared, and the sab becomes ready for the next operation. the cancel_access instruction pr ovides a possibility to abort an ongoing transfer and report a timeout to the jtag master. when the cancel_access instruction is select ed, the current access will be terminated as soon as possible. there are no guarantees about how long this will take, as the hardware may not always be able to cancel the access immedi ately. the sab is ready to respond to a new command when the busy bit clears. starting in run-test/idl e, cancel_access is acce ssed in the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. return to run-test/idle. 34.5.3.7 sync this instruction allows external debuggers and testers to measure the ratio between the external jtag clock and the internal system clock. the sync data register is a 16-bit counter that counts down to zero using the internal system clock. the busy bit stays high until the counter reaches zero. starting in run-test/idle, sync inst ruction is used in the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. return to run-test/idle. 5. select the dr scan path. dr input value (data write phase) dddddddd dddddddd dddddddd dddddddd xx dr output value (data read phase) eb dddddddd dddddddd dddddddd dddddddd dr output value (data write phase) xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxeb table 34-21. memory_block_access details (continued) instructions details table 34-22. cancel_access details instructions details ir input value 10011 (0x13) ir output value peb01 dr size 1 dr input value x dr output value 0
972 32072d?04/2011 at32uc3a3/a4 6. scan in an 16-bit counter value. 7. go to update-dr and re-enter select-dr scan. 8. in shift-dr: scan out the busy bit, and until the busy bit clears goto 7. 9. calculate an approximation to the internal clock speed using the elapsed time and the counter value. 10. return to run-test/idle. the full 16-bit counter value must be provided when starting the synch operation, or the result will be undefined. when r eading status, shifting may be term inated once the required number of bits have been acquired. 34.5.3.8 avr_reset this instruction allows a debugger or tester to directly control separate reset domains inside the chip. the shift register contains one bit for each controllable reset domain. setting a bit to one resets that domain and holds it in reset. setting a bit to zero releases the reset for that domain. the avr_reset instruction can be used in the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. return to run-test/idle. 5. select the dr scan path. 6. in shift-dr: scan in the value corresponding to the reset domains the jtag master wants to reset into the data register. 7. return to run-test/idle. 8. stay in run test idle for at least 10 tck clock cycles to let the reset propagate to the system. see the device specific document ation for the number of reset domains, and what these domains are. for any operation, all bits must be provided or th e result will be undefined. table 34-23. sync_access details instructions details ir input value 10111 (0x17) ir output value peb01 dr size 16 bits dr input value dddddddd dddddddd dr output value xxxxxxxx xxxxxxeb table 34-24. avr_reset details instructions details ir input value 01100 (0x0c) ir output value p0001
973 32072d?04/2011 at32uc3a3/a4 34.5.3.9 chip_erase this instruction allows a programmer to completely erase all nonvolatile memories in a chip. this will also clear any security bits that are set, so the device can be accessed normally. in devices without non-volatile memories this instruction does nothing, and appears to complete immediately. the erasing of non-volatile memo ries starts as soon as the chi p_erase instruction is selected. the chip_erase instruction selects a 1 bit bypass data register. a chip erase operation should be performed as: 1. reset the system and stop the cpu from executing. 2. select the ir scan path. 3. in capture-ir: the ir output value is latched into the shift register. 4. in shift-ir: the instruction register is shifted by the tck input. 5. check the busy bit that was scanned out during shift-ir. if the busy bit was set goto 2. 6. return to run-test/idle. 34.5.3.10 halt this instruction allows a programmer to easily stop the cpu to ensure that it does not execute invalid code during programming. this instruction selects a 1-bit halt register. setting this bit to one resets the device and halts the cpu. setting this bit to zero resets the device and releases the cpu to run normally. the value shifted out from the data register is one if the cpu is halted. the halt instruction can be used in the following way: 1. select the ir scan path. 2. in capture-ir: the ir output value is latched into the shift register. 3. in shift-ir: the instruction register is shifted by the tck input. 4. return to run-test/idle. 5. select the dr scan path. dr size device specific. dr input value device specific. dr output value device specific. table 34-24. avr_reset details (continued) instructions details table 34-25. chip_erase details instructions details ir input value 01111 (0x0f) ir output value p0b01 where b is the busy bit. dr size 1 bit dr input value x dr output value 0
974 32072d?04/2011 at32uc3a3/a4 6. in shift-dr: scan in the value 1 to halt the cpu, 0 to start cpu execution. 7. return to run-test/idle. table 34-26. halt details instructions details ir input value 11100 (0x1c) ir output value p0001 dr size 1 bit dr input value d dr output value d
975 32072d?04/2011 at32uc3a3/a4 34.5.4 jtag data registers the following device specific registers can be selected as jtag scan chain depending on the instruction loaded in the jtag instruction register. additional registers exist, but are implicitly described in the functional description of the relevant instructions. 34.5.4.1 device identification register the device identification register contains a unique identifier for each product. the register is selected by the idcode instruction, which is the default instruction after a jtag reset. ?device specific id codes the different device configurations have different jtag id codes, as shown in table 34-27 . note that if the flash co ntroller is statically rese t, the id code will be undefined . msb lsb bit 31 28 27 12 11 1 0 device id revision part number manufacturer id 1 4 bits 16 bits 11 bits 1 bit revision this is a 4 bit number identifyin g the revision of the component. rev a = 0x0, b = 0x1, etc. part number the part number is a 16 bit co de identifying the component. manufacturer id the manufacturer id is a 11 bit code identifying the manufacturer. the jtag manufacturer id for atmel is 0x01f. table 34-27. device and jtag id device name jtag id code (r is the revision number) at32uc3a3256s 0xr202003f at32uc3a3128s 0xr202103f at32uc3a364s 0xr202203f at32uc3a3256 0xr202603f at32uc3a3128 0xr202703f at32uc3a364 0xr202803f at32uc3a4256s 0xr202903f at32uc3a4128s 0xr202a03f at32uc3a464s 0xr202b03f at32uc3a4256 0xr202c03f at32uc3a128 0xr202d03f at32uc3a64 0xr202e03f
976 32072d?04/2011 at32uc3a3/a4 34.5.4.2 reset register the reset register is selected by the avr_reset instruction and co ntains one bit for each reset domain in the device. se tting each bit to one will keep that domain reset until the bit is cleared. note: this register is primarily intended for com patibility with other 32-bit avr devices. certain operations may not function correctly when parts of the system are reset. it is generally recom- mended to only write 0x11111 or 0x00000 to these bits to ensure no unintended side effects occur. 34.5.4.3 boundary-scan chain the boundary-scan chain has the ca pability of driving an d observing the logic levels on the dig- ital i/o pins, as well as driving and observing the logic levels between the digital i/o pins and the internal logic. typically, output value, output enable, and input data are all available in the boundary scan chain. the boundary scan chain is described in the bdsl (boundary scan description language) file available at the atmel web site. lsb bit 43210 device id ocd app reserved reserved cpu cpu cpu app hsb and pb buses ocd on-chip debug logic and registers rserved no effect
977 32072d?04/2011 at32uc3a3/a4 35. electrical characteristics 35.1 absolute maximum ratings* operating temperature.................................... -40c to +85c *notice: stresses beyond those listed under ?absolute maximum ratings? may cause permanent dam- age to the device. this is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. exposure to absolute maximum rating conditions for extended periods may affect device reliability. storage temperature ..................................... -60c to +150c voltage on input pin with respect to ground ........................................-0.3v to 3.6v maximum operating voltage (vddcore) ..................... 1.95v maximum operating voltage (vddio).............................. 3.6v total dc output current on all i/o pin for tqfp144 package ................................................. 370 ma for tfbga144 package ............................................... 370 ma
978 32072d?04/2011 at32uc3a3/a4 35.2 dc characteristics the following characteristics are applicable to the operating temperature range: t a = -40c to 85c, unless otherwise specified and are certified for a junction temperature up tot j =100c. table 35-1. dc characteristics symbol parameter conditions min. typ. max. unit v vddio dc supply peripheral i/os 3.0 3.6 v v vddana dc analog supply 3.0 3.6 v v il input low-level voltage all i/o pins except twck, twd, reset_n, tck, tdi -0.3 +0.8 v twck, twd v vddio x0.7 v vddio +0.5 v reset_n, tck, tdi +0.8v v v ih input high-level voltage all i/o pins except twck, twd 2.0 3.6 v twck, twd v v ol output low-level voltage i ol = -2ma for pin drive x1 i ol = -4ma for pin drive x2 i ol = -8ma for pin drive x3 0.4 v v oh output high-level voltage i oh = 2ma for pin drive x1 i oh = 4ma for pin drive x2 i oh = 8ma for pin drive x3 v vddio -0.4 v i leak input leakage current pullup resistors disabled 0.05 1 a c in input capacitance 7pf r pullup pull-up resistance all i/o pins except reset_n, tck, tdi, tms 91525k reset_n, tck, tdi, tms 5 25 k i o output current pin drive 1x pin drive 2x pin drive 3x 2.0 4.0 8.0 ma i sc static current on v vddin = 3.3v, cpu in static mode t a = 25c 30 a t a = 85c 175 a
979 32072d?04/2011 at32uc3a3/a4 35.2.1 i/o pin output level typical characteristics figure 35-1. i/o pin drive x2 output low level voltage (vol) vs. source current figure 35-2. i/o pin drive x2 output high level voltage (voh) vs. source current 35.3 i/o pin characteristics these parameters are given in the following conditions: ?v ddcore = 1.8v ?v ddio = 3.3v ? ambient temperature = 25c vddio = 3.3v 90 25 -45 0 0,2 0,4 0,6 0,8 1 1,2 1,4 1,6 1,8 0 5 10 15 20 load current [ma] voltage [v] vddio = 3.3v 90 25 -45 0 0,5 1 1,5 2 2,5 3 3,5 0 5 10 15 20 load current [ma] voltage [v]
980 32072d?04/2011 at32uc3a3/a4 35.4 regulator characteristics table 35-2. normal i/o pin characteristics symbol parameter conditions drive x2 drive x2 drive x3 unit f max output frequency 10pf 40 66 100 mhz 30pf 18.2 35.7 61.6 mhz 60pf 7.5 18.5 36.3 mhz t rise rise time 10pf 2.7 1.4 0.9 ns 30pf 6.9 3.5 1.9 ns 60pf 13.4 6.7 3.5 ns t fall fall time 10pf 3.2 1.7 0.9 ns 30pf 8.6 4.3 2.26 ns 60pf 16.5 8.3 4.3 ns table 35-3. electrical characteristics symbol parameter conditions min. typ. max. unit v vddin supply voltage (input) 3.0 3.3 3.6 v v vddcore supply voltage (output) 1.75 1.85 1.95 v i out maximum dc output current v vddin = 3.3v 100 ma table 35-4. decoupling requirements symbol parameter conditions typ. technology unit c in1 input regulator capacitor 1 1 npo nf c in2 input regulator capacitor 2 4.7 x7r f c out1 output regulator capacitor 1 470 npo pf c out2 output regulator capacitor 2 2.2 x7r f
981 32072d?04/2011 at32uc3a3/a4 35.5 analog characteristics 35.5.1 adc 35.5.2 bod table 35-7 describes the values of the bodlevel field in the flash fgpfr register. table 35-8 describes the values of the bo d33.level field in the pm module table 35-5. electrical characteristics symbol parameter conditions min. typ. max. unit v vddana analog power supply 3.0 3.6 v table 35-6. decoupling requirements symbol parameter conditions typ. technology unit c vddana power supply capacitor 100 npo nf table 35-7. 1.8v bod level values symbol parameter value conditions min. typ. max. unit bodlevel 00 1111b 1.79 v 01 0111b 1.70 v 01 1111b 1.61 v 10 0111b 1.52 v table 35-8. 3.3v bod level values symbol parameter value conditions min. typ. max. unit bod33level reset value 2.71 v 1011 2.27 v 1010 2.37 v 1001 2.46 v 1000 2.56 v 0111 2.66 v 0110 2.76 v 0101 2.86 v 0100 2.96 v 0011 3.06 v 0010 3.15 v 0001 3.25 v 0000 3.35 v
982 32072d?04/2011 at32uc3a3/a4 35.5.3 reset sequence table 35-9. bod timing symbol parameter conditions min. typ. max. unit t bod minimum time with vddcore < vbod to detect power failure falling vddcore from 1.8v to 1.1v 300 800 ns table 35-10. electrical characteristics symbol parameter conditions min. typ. max. unit v ddrr vddin/vddio rise rate to ensure power-on-reset 0.8 v/ms v por+ rising threshold voltage: voltage up to which device is kept under reset by por on rising vddin rising vddin: v restart -> v por+ 2.7 v v por- falling threshold voltage: voltage when por resets device on falling vddin falling vddin: 3.3v -> v por- 2.7 v v restart on falling vddin, voltage must go down to this value before supply can rise again to ensure reset signal is released at v por+ falling vddin: 3.3v -> v restart 0.2 v t ssu1 time for cold system startup: time for cpu to fetch its first instruction (rcosc not calibrated) 480 960 s t ssu2 time for hot system startup: time for cpu to fetch its first instruction (rcosc calibrated) 420 s
983 32072d?04/2011 at32uc3a3/a4 figure 35-3. mcu cold start-up figure 35-4. mcu cold start-up rese t_n externally driven figure 35-5. mcu hot start-up v bod33level vddin vddio internal mcu reset t ssu1 internal bod33 reset reset_n v restart v bod33level v bod33level vddin vddio internal mcu reset t ssu1 internal bod33 reset reset_n v restart v bod33level vddin vddio internal mcu reset t ssu2 reset_n bod reset wdt reset
984 32072d?04/2011 at32uc3a3/a4 35.5.4 reset_n characteristics table 35-11. reset_n waveform parameters symbol parameter conditions min. typ. max. unit t reset reset_n minimum pulse width 10 ns
985 32072d?04/2011 at32uc3a3/a4 35.6 power consumption the values in table 35-12 and table 35-13 on page 987 are measured values of power con- sumption with operating conditions as follows: ?v ddio = 3.3v ?t a = 25 c ?i/os are configured in input, pull-up enabled. figure 35-6. measurement setup these figures represent the power consum ption measured on the power supplies internal voltage regulator amp0 vddana vddio vddin vddcore gndpll gndcore
986 32072d?04/2011 at32uc3a3/a4 35.6.1 power consumtion for different sleep modes notes: 1. core frequency is generated from xin0 using the pll. table 35-12. power consumption for different sleep modes mode conditions (1) typ. unit active - cpu running a recursive fibonacci algorithm from flash and clocked from pll0 at f mhz. - voltage regulator is on. - xin0: external clock. xin1 stopped. xin32 stopped. - all peripheral clocks activated with a division by 8. - gpios are inactive with internal pu ll-up, jtag unconnected with external pullup and input pins are connected to gnd 0.626xf(mhz)+2.257 ma/mhz same conditions at 60 mhz 40 ma idle see active mode conditions 0.349xf(mhz)+0.968 ma/mhz same conditions at 60 mhz 21.8 ma frozen see active mode conditions 0.098xf(mhz)+1.012 ma/mhz same conditions at 60 mhz 6.6 ma standby see active mode conditions 0.066xf(mhz)+1.010 ma/mhz same conditions at 60 mhz 4.6 ma stop - cpu running in sleep mode - xin0, xin1 and xin32 are stopped. - all peripheral clocks are desactived. - gpios are inactive with internal pu ll-up, jtag unconnected with external pullup and input pins are connected to gnd. 96 a deepstop see stop mode conditions 54 a static t a = 25 c cpu is in static mode gpios on internal pull-up all peripheral clocks de-activated dm and dp pins connected to ground xin0, xin1 and xin32 are stopped on amp0 31 a
987 32072d?04/2011 at32uc3a3/a4 table 35-13. typical cuurent consumption by peripheral peripheral typ. unit adc 7 a/mhz aes 80 abdac 10 dmaca 70 ebi 23 eic 0.5 gpio 37 intc 3 mci 40 msi 10 pdca 20 sdram 5 smc 9 spi 6 ssc 10 rtc 5 tc 8 twim 2 twis 2 usart 10 usbb 90 wdt 2
988 32072d?04/2011 at32uc3a3/a4 35.7 system clock characteristics these parameters are given in the following conditions: ?v ddcore = 1.8v ? ambient temperature = 25c 35.7.1 cpu/hsb clock characteristics 35.7.2 pba clock characteristics 35.7.3 pbb clock characteristics table 35-14. core clock waveform parameters symbol parameter conditions min. typ. max. unit 1/(t cpcpu ) cpu clock frequency 66 mhz t cpcpu cpu clock period 15,15 ns table 35-15. pba clock waveform parameters symbol parameter conditions min. typ. max. unit 1/(t cppba ) pba clock frequency 66 mhz t cppba pba clock period 15.15 ns table 35-16. pbb clock waveform parameters symbol parameter conditions min. typ. max. unit 1/(t cppbb ) pbb clock frequency 66 mhz t cppbb pbb clock period 15.15 ns
989 32072d?04/2011 at32uc3a3/a4 35.8 oscillator characteristics the following characteristics are applicabl e to the operating temperature range: t a = -40c to 85c and worst case of power supply, unless otherwise specified. 35.8.1 slow clock rc oscillator 35.8.2 32 khz oscillator note: 1. c l is the equivalent load capacitance. table 35-17. rc oscillator frequency symbol parameter conditions min. typ. max. unit f rc rc oscillator frequency calibration point: t a = 85c 115.2 116 khz t a = 25c 112 khz t a = -40c 105 108 khz table 35-18. 32 khz oscillator characteristics symbol parameter conditions min. typ. max. unit 1/(t cp32khz ) oscillator frequency external clock on xin32 30 mhz crystal 32 768 hz c l equivalent load capacitance 6 12.5 pf esr crystal equivalent series resistance 100 k t st startup time c l = 6pf (1) c l = 12.5pf (1) 600 1200 ms t ch xin32 clock high half-period 0.4 t cp 0.6 t cp t cl xin32 clock low half-period 0.4 t cp 0.6 t cp c in xin32 input capacitance 5pf i osc current consumption active mode 1.8 a standby mode 0.1 a
990 32072d?04/2011 at32uc3a3/a4 35.8.3 main oscillators 35.8.4 phase lock loop table 35-19. main oscillators characteristics symbol parameter conditions min. typ. max. unit 1/(t cpmain ) oscillator frequency external clock on xin 50 mhz crystal 0.4 20 mhz c l1 , c l2 internal load capacitance (c l1 = c l2 )7pf esr crystal equivalent series resistance 75 duty cycle 405060 % t st startup time f = 400 khz f = 8 mhz f = 16 mhz f = 20 mhz ms t ch xin clock high half-period 0.4 t cp 0.6 t cp t cl xin clock low half-period 0.4 t cp 0.6 t cp c in xin input capacitance 7 pf i osc current consumption active mode at 400 khz. gain = g0 30 a active mode at 8 mhz. gain = g1 45 a active mode at 16 mhz. gain = g2 95 a active mode at 20 mhz. gain = g3 205 a table 35-20. pll characteristics symbol parameter conditions min. typ. max. unit f out vco output frequency 80 240 mhz f in input frequency (after input divider) 4 16 mhz i pll current consumption active mode (fout=80 mhz) 250 a active mode (fout=240 mhz) 600 a
991 32072d?04/2011 at32uc3a3/a4 35.9 adc characteristics table 35-21. channel conversion time and adc clock parameter conditions min. typ. max. unit adc clock frequency 10-bit resolution mode 5 mhz 8-bit resolution mode 8 mhz startup time return from idle mode 20 s track and hold acquisition time 600 ns conversion time adc clock = 5 mhz 2 s adc clock = 8 mhz 1.25 s throughput rate adc clock = 5 mhz 384 (1) 1. corresponds to 13 clock cycles: 3 clock cycles for track a nd hold acquisition time and 10 clock cycles for conversion. ksps adc clock = 8 mhz 533 (2) 2. corresponds to 15 clock cycles: 5 clock cycles for track a nd hold acquisition time and 10 clock cycles for conversion. ksps table 35-22. adc power consumption parameter conditions min. typ. max. unit current consumption on vddana (1) 1. including internal re ference input current on 13 samples with adc clock = 5 mhz 1.25 ma table 35-23. analog inputs parameter conditions min. typ. max. unit input voltage range 0 vddana v input leakage current 1a input capacitance 7pf input resistance 350 850 ohm table 35-24. transfer characteristics in 8-bit mode parameter conditions min. typ. max. unit resolution 8bit absolute accuracy adc clock = 5 mhz 0.8 lsb adc clock = 8 mhz 1.5 lsb integral non-linearity adc clock = 5 mhz 0.35 0.5 lsb adc clock = 8 mhz 0.5 1.0 lsb differential non-linearity adc clock = 5 mhz 0.3 0.5 lsb adc clock = 8 mhz 0.5 1.0 lsb offset error adc clock = 5 mhz -0.5 0.5 lsb gain error adc clock = 5 mhz -0.5 0.5 lsb
992 32072d?04/2011 at32uc3a3/a4 35.10 usb transceiver characteristics 35.10.1 electrical characteristics 35.10.2 static power consumption 35.10.3 dynamic power consumption table 35-25. transfer characteristics in 10-bit mode parameter conditions min. typ. max. unit resolution 10 bit absolute accuracy adc clock = 5 mhz 3 lsb integral non-linearity adc clock = 5 mhz 1.5 2 lsb differential non-linearity adc clock = 5 mhz 1 2 lsb adc clock = 2.5 mhz 0.6 1 lsb offset error adc clock = 5 mhz -2 2 lsb gain error adc clock = 5 mhz -2 2 lsb table 35-26. electrical parameters symbol parameter conditions min. typ. max. unit r ext recommended external usb series resistor in series with each usb pin with 5% 39 r bias vbias external resistor (1) 1. the usb on-chip buffers comply with the universal serial bus (usb) v2.0 standard. all ac parameters related to these buf- fers can be found within the usb 2. 0 electrical specifications. 1% 6810 c bias vbias external capcitor 10 pf table 35-27. static power consumption symbol parameter conditions min. typ. max. unit i bias bias current consumption on vbg 1 a i vddutmi hs transceiver and i/o current consumption 8a fs/hs transceiver and i/o current consumption if cable is connected, add 200a (typical) due to pull-up/pull-down current consumption 3a table 35-28. dynamic power consumption symbol parameter conditions min. typ. max. unit i bias bias current consumption on vbg 0.7 0.8 ma
993 32072d?04/2011 at32uc3a3/a4 i vddutmi hs transceiver current consumption hs transmission 47 60 ma hs transceiver current consumption hs reception 18 27 ma fs/hs transceiver current consumption fs transmission 0m cable (1) 46ma fs/hs transceiver current consumption fs transmission 5m cable 26 30 ma fs/hs transceiver current consumption fs reception 3 4.5 ma 1. including 1 ma due to pull-up/pull-down current consumption. 34.5.5 usb high speed design guidelines in order to facilitate hardware design, atmel provides an application note on www.atmel.com . table 35-28. dynamic power consumption symbol parameter conditions min. typ. max. unit
994 32072d?04/2011 at32uc3a3/a4 35.11 ebi timings 35.11.1 smc signals these timings are given for worst case process, t = 85 ? c, vddio = 3v and 40 pf load capacitance. note: 1. the maximum frequency of the smc interface is the same as the max frequency for the hsb. note: 1. hold length = total cycle duration - setup duration - pulse duration. ?hold length? is for ?ncs rd hold length? or ?nrd hold length?. table 35-29. smc clock signal symbol parameter max. (1) unit 1/(t cpsmc ) smc controller clock frequency 1/(t cpcpu )mhz table 35-30. smc read signals with hold settings symbol parameter min. unit nrd controlled (read_mode = 1) smc 1 data setup before nrd high 12 ns smc 2 data hold after nrd high 0 ns smc 3 nrd high to nbs0/a0 change (1) nrd hold length * t cpsmc - 1.3 ns smc 4 nrd high to nbs1 change (1) nrd hold length * t cpsmc - 1.3 ns smc 5 nrd high to nbs2/a1 change (1) nrd hold length * t cpsmc - 1.3 ns smc 7 nrd high to a2 - a23 change (1) nrd hold length * t cpsmc - 1.3 ns smc 8 nrd high to ncs inactive (1) (nrd hold length - ncs rd hold length) * t cpsmc - 2.3 ns smc 9 nrd pulse width nrd pulse length * t cpsmc - 1.4 ns nrd controlled (read_mode = 0) smc 10 data setup before ncs high 11.5 ns smc 11 data hold after ncs high 0 ns smc 12 ncs high to nbs0/a0 change (1) ncs rd hold length * t cpsmc - 2.3 ns smc 13 ncs high to nbs0/a0 change (1) ncs rd hold length * t cpsmc - 2.3 ns smc 14 ncs high to nbs2/a1 change (1) ncs rd hold length * t cpsmc - 2.3 ns smc 16 ncs high to a2 - a23 change (1) ncs rd hold length * t cpsmc - 4ns smc 17 ncs high to nrd inactive (1) ncs rd hold length - nrd hold length)* t cpsmc - 1.3 ns smc 18 ncs pulse width ncs rd pulse length * t cpsmc - 3.6 ns
995 32072d?04/2011 at32uc3a3/a4 note: 1. hold length = total cycle duration - setup duration - pulse duration. ?hold length? is for ?ncs wr hold length? or ?nwe hold length" table 35-31. smc read signals with no hold settings symbol parameter min. unit nrd controlled (read_mode = 1) smc 19 data setup before nrd high 13.7 ns smc 20 data hold after nrd high 1 ns nrd controlled (read_mode = 0) smc 21 data setup before ncs high 13.3 ns smc 22 data hold after ncs high 0 ns table 35-32. smc write signals with hold settings symbol parameter min. unit nrd controlled (read_mode = 1) smc 23 data out valid before nwe high (nwe pulse length - 1) * t cpsmc - 0.9 ns smc 24 data out valid after nwe high (1) nwe hold length * t cpsmc - 6 ns smc 25 nwe high to nbs0/a0 change (1) nwe hold length * t cpsmc - 1.9 ns smc 26 nwe high to nbs1 change (1) nwe hold length * t cpsmc - 1.9 ns smc 29 nwe high to a1 change (1) nwe hold length * t cpsmc - 1.9 ns smc 31 nwe high to a2 - a23 change (1) nwe hold length * t cpsmc - 1.7 ns smc 32 nwe high to ncs inactive (1) (nwe hold length - ncs wr hold length)* t cpsmc - 2.9 ns smc 33 nwe pulse width nwe pulse length * t cpsmc - 0.9 ns nrd controlled (read_mode = 0) smc 34 data out valid before ncs high (ncs wr pulse length - 1)* t cpsmc - 4.6 ns smc 35 data out valid after ncs high (1) ncs wr hold length * t cpsmc - 5.8 ns smc 36 ncs high to nwe inactive (1) (ncs wr hold length - nwe hold length)* t cpsmc - 0.6 ns table 35-33. smc write signals with no hold settings (nwe controlled only) symbol parameter min. unit smc 37 nwe rising to a2-a25 valid 5.4 ns smc 38 nwe rising to nbs0/a0 valid 5 ns smc 39 nwe rising to nbs1 change 5 ns smc 40 nwe rising to a1/nbs2 change 5 ns smc 41 nwe rising to nbs3 change 5 ns smc 42 nwe rising to ncs rising 5.1 ns
996 32072d?04/2011 at32uc3a3/a4 figure 35-7. smc signals for ncs controlled accesses. smc 43 data out valid before nwe rising (nwe pulse length - 1) * t cpsmc - 1.2 ns smc 44 data out valid after nwe rising 5 ns smc 45 nwe pulse width nwe pulse length * t cpsmc - 0.9 ns table 35-33. smc write signals with no hold settings (nwe controlled only) symbol parameter min. unit nrd ncs d0 - d15 nwe a2-a25 a0/a1/nbs[3:0] smc34 smc35 smc10 smc11 smc16 smc15 smc22 smc21 smc17 smc18 smc14 smc13 smc12 smc18 smc17 smc16 smc15 smc14 smc13 smc12 smc18 smc36 smc16 smc15 smc14 smc13 smc12
997 32072d?04/2011 at32uc3a3/a4 figure 35-8. smc signals for nrd and nrw controlled accesses. 35.11.2 sdram signals these timings are given for 10 pf load on sdck and 40 pf on other signals. note: 1. the maximum frequency of the sdramc interface is the same as the max frequency for the hsb. nrd ncs d0 - d15 nwe a2-a25 a0/a1/nbs[3:0] smc7 smc19 smc20 smc43 smc37 smc42 smc8 smc1 smc2 smc23 smc24 smc32 smc7 smc8 smc6 smc5 smc4 smc3 smc9 smc41 smc40 smc39 smc38 smc45 smc9 smc6 smc5 smc4 smc3 smc33 smc30 smc29 smc26 smc25 smc31 smc44 table 35-34. sdram clock signal. symbol parameter conditions min. max. (1) unit 1/(t cpsdck ) sdram controller clock frequency 1/(t cpcpu )mhz table 35-35. sdram clock signal symbol parameter conditions min. max. unit sdramc 1 sdcke high before sdck rising edge 7.4 ns sdramc 2 sdcke low after sdck rising edge 3.2 ns sdramc 3 sdcke low before sdck rising edge 7 ns sdramc 4 sdcke high after sdck rising edge 2.9 ns sdramc 5 sdcs low before sdck rising edge 7.5 ns sdramc 6 sdcs high after sdck rising edge 1.6 ns sdramc 7 ras low before sdck rising edge 7.2 ns sdramc 8 ras high after sdck rising edge 2.3 ns sdramc 9 sda10 change before sdck rising edge 7.6 ns sdramc 10 sda10 change after sdck rising edge 1.9 ns sdramc 11 address change before sdck rising edge 6.2 ns sdramc 12 address change after sdck rising edge 2.2 ns
998 32072d?04/2011 at32uc3a3/a4 sdramc 13 bank change before sdck rising edge 6.3 ns sdramc 14 bank change after sdck rising edge 2.4 ns sdramc 15 cas low before sdck rising edge 7.4 ns sdramc 16 cas high after sdck rising edge 1.9 ns sdramc 17 dqm change before sdck rising edge 6.4 ns sdramc 18 dqm change after sdck rising edge 2.2 ns sdramc 19 d0-d15 in setup before sdck rising edge 9 ns sdramc 20 d0-d15 in hold after sdck rising edge 0 ns sdramc 23 sdwe low before sdck rising edge 7.6 ns sdramc 24 sdwe high after sdck rising edge 1.8 ns sdramc 25 d0-d15 out valid before sdck rising edge 7.1 ns sdramc 26 d0-d15 out valid after sdck rising edge 1.5 ns table 35-35. sdram clock signal symbol parameter conditions min. max. unit
999 32072d?04/2011 at32uc3a3/a4 figure 35-9. sdramc signals relative to sdck. ras a0 - a9, a11 - a13 d0 - d15 read sdck sda10 d0 - d15 to write sdramc 1 sdcke sdramc 2 sdramc 3 sdramc 4 sdcs sdramc 5 sdramc 6 sdramc 5 sdramc 6 sdramc 5 sdramc 6 sdramc 7 sdramc 8 cas sdramc 15 sdramc 16 sdramc 15 sdramc 16 sdwe sdramc 23 sdramc 24 sdramc 9 sdramc 10 sdramc 9 sdramc 10 sdramc 9 sdramc 10 sdramc 11 sdramc 12 sdramc 11 sdramc 12 sdramc 11 sdramc 12 ba0/ba1 sdramc 13 sdramc 14 sdramc 13 sdramc 14 sdramc 13 sdramc 14 sdramc 17 sdramc 18 sdramc 17 sdramc 18 dqm0 - dqm3 sdramc 19 sdramc 20 sdramc 25 sdramc 26
1000 32072d?04/2011 at32uc3a3/a4 35.12 jtag characteristics 35.12.1 jtag interface signals table 35-36. jtag interface timing specification symbol parameter conditions (1) 1. v vddio from 3.0v to 3.6v, maximum external capacitor = 40pf min. max. unit jtag 0 tck low half-period 6 ns jtag 1 tck high half-period 3 ns jtag 2 tck period 9ns jtag 3 tdi, tms setup be fore tck high 1 ns jtag 4 tdi, tms hold after tck high 0 ns jtag 5 tdo hold time 4 ns jtag 6 tck low to tdo valid 6ns jtag 7 device inputs setup time ns jtag 8 device inputs hold time ns jtag 9 device outputs hold time ns jtag 10 tck to device outputs valid ns
1001 32072d?04/2011 at32uc3a3/a4 figure 35-10. jtag interface signals 35.13 spi characteristics figure 35-11. spi master mode with (cpol= nc pha= 0) or (cpol= ncpha= 1) tck jtag 9 tms/tdi tdo device outputs jtag 5 jtag 4 jtag 3 jtag 0 jtag 1 jtag 2 jtag 10 device inputs jtag 8 jtag 7 jtag 6 spck miso mosi spi 2 spi 0 spi 1
1002 32072d?04/2011 at32uc3a3/a4 figure 35-12. spi master mode with (cpol= 0 and ncpha= 1) or (cpol= 1 and ncpha= 0) figure 35-13. spi slave mode with (cpol= 0 and ncpha= 1) or (cpol= 1 and ncpha= 0) figure 35-14. spi slave mode with (cpol= ncp ha= 0) or (cpol= ncpha= 1) spck miso mosi spi 5 spi 3 spi 4 spck miso mosi spi 6 spi 7 spi 8 spck miso mosi spi 9 spi 10 spi 11
1003 32072d?04/2011 at32uc3a3/a4 35.14 mci the high speed multimedia card interface (mci) suppor ts the multimedia ca rd (mmc) specifi- cation v4.2, the sd memory card specificatio n v2.0, the sdio v1.1 specification and ce-ata v1.1. 35.14.1 load characteristics table 35-37. spi timings symbol parameter conditions (1) 1. 3.3v domain: v vddio from 3.0v to 3.6v, maximum external capacitor = 40 pf min. max. unit spi 0 miso setup time before spck rises (master) 3.3v domain 22 + (t cpmck )/2 (2) 2. t cpmck : master clock period in ns. ns spi 1 miso hold time after spck rises (master) 3.3v domain 0 ns spi 2 spck rising to mosi delay (master) 3.3v domain 7 ns spi 3 miso setup time before spck fall s (master) 3.3v domain 22 + (t cpmck )/2 (3) 3. t cpmck : master clock period in ns. ns spi 4 miso hold time after spck falls (master) 3.3v domain 0 ns spi 5 spck falling to mosi delay master) 3.3v domain 7 ns spi 6 spck falling to miso delay (slave) 3.3v domain 26.5 ns spi 7 mosi setup time before spck rises (slave) 3.3v domain 0 ns spi 8 mosi hold time after spck rises (slave) 3.3v domain 1.5 ns spi 9 spck rising to miso delay (slave) 3.3v domain 27 ns spi 10 mosi setup time before spck falls (slave) 3.3v domain 0 ns spi 11 mosi hold time after spck falls (slave) 3.3v domain 1 ns table 35-38. load parameter symbol parameter conditions min. typ. max. unit c load signal load capacitance f mci = 33 mhz 30 pf
1004 32072d?04/2011 at32uc3a3/a4 35.15 flash memory characteristics the following table gives the device maximum op erating frequency depending on the field fws of the flash fsr register. this field defines the number of wait states required to access the flash memory. flash operating freque ncy equals the cpu/hsb frequency. table 35-39. flash operating frequency symbol parameter conditions min. typ. max. unit f fop flash operating frequency fws = 0 36 mhz fws = 1 66 mhz table 35-40. parts programming time symbol parameter conditions min. typ. max. unit t fpp page programming time 5 ms t ffp fuse programming time 0.5 ms t fce chip erase time 8ms table 35-41. flash parameters symbol parameter conditions min. typ. max. unit n farray flash array write/erase cycle 100k cycle n ffuse general purpose fuses write cycle 1000 cycle t fdr flash data retention time 15 year
1005 32072d?04/2011 at32uc3a3/a4 36. mechanical characteristics 36.1 thermal considerations 36.1.1 thermal data table 36-1 summarizes the thermal resistance data depending on the package. 36.1.2 junction temperature the average chip-junction temperature, t j , in c can be obtained from the following: 1. 2. where: ? ja = package thermal resistance, junction-to-ambient (c/w), provided in table 36-1 on page 1005 . ? jc = package thermal resistance, junction-to-ca se thermal resistance (c/w), provided in table 36-1 on page 1005 . ? heat sink = cooling device thermal resistance (c/w), provided in the device datasheet. ?p d = device power consumption (w) estimated from data provided in the section ?regulator characteristics? on page 980 . ?t a = ambient temperature (c). from the first equation, the user can derive the estimated lifetime of the chip and decide if a cooling device is necessary or not. if a coolin g device is to be fitted on the chip, the second equation should be used to compute the resulting average chip-junction temperature t j in c. table 36-1. thermal resistance data symbol parameter condition package typ unit ja junction-to-ambient thermal resistance still air tqfp144 40.3 c/w jc junction-to-case thermal resistance tqfp144 9.5 ja junction-to-ambient thermal resistance still air tfbga144 28.5 c/w jc junction-to-case thermal resistance tfbga144 6.9 ja junction-to-ambient thermal resistance still air vfbga100 31.1 c/w jc junction-to-case thermal resistance vfbga100 6.9 t j t a p d ja () + = t j t a p ( d ( heatsink jc )) ++ =
1006 32072d?04/2011 at32uc3a3/a4 36.2 package drawings figure 36-1. tfbga 144 package drawing
1007 32072d?04/2011 at32uc3a3/a4 figure 36-2. lqfp-144 package drawing table 36-2. device and package maximum weight 1300 mg table 36-3. package characteristics moisture sensitivity level msl3 table 36-4. package reference jedec drawing reference ms-026 jesd97 classification e3
1008 32072d?04/2011 at32uc3a3/a4 figure 36-3. vfbga-100 package drawing
1009 32072d?04/2011 at32uc3a3/a4 36.3 soldering profile table 36-5 gives the recommended soldering profile from j-std-20. note: it is recommended to apply a soldering temperature higher than 250c. a maximum of three reflow passes is allowed per component. table 36-5. soldering profile profile feature green package average ramp-up rate (217c to peak) 3c/second max preheat temperature 175c 25c 150-200c time maintained above 217c 60-150 seconds time within 5 c of actual peak temperature 30 seconds peak temperature range 260 (+0/-5c) ramp-down rate 6c/second max. time 25 c to peak temperature 8 minutes max
1010 32072d?04/2011 at32uc3a3/a4 37. ordering information device ordering code package conditioning temperature operating range at32uc3a3256s at32uc3a3256s-alut 144-lead lqfp tray industrial (-40 ? c to 85 ? c) at32uc3a3256s-alur 144-lead lqfp reels industrial (-40 ? c to 85 ? c) at32uc3a3256s-ctut 144-ball tfbga tray industrial (-40 ? c to 85 ? c) at32uc3a3256s-ctur 144-ball tfbga reels industrial (-40 ? c to 85 ? c) at32uc3a3256 at32uc3a3256-alut 144-lead lqfp tray industrial (-40 ? c to 85 ? c) at32uc3a3256-alur 144-lead lqfp reels industrial (-40 ? c to 85 ? c) at32uc3a3256-ctut 144-ball tfbga tray industrial (-40 ? c to 85 ? c) at32uc3a3256-ctur 144-ball tfbga reels industrial (-40 ? c to 85 ? c) at32uc3a3128s at32uc3a3128s-alut 144-lead lqfp tray industrial (-40 ? c to 85 ? c) at32uc3a3128s-alur 144-lead lqfp reels industrial (-40 ? c to 85 ? c) at32uc3a3128s-ctut 144-ball tfbga tray industrial (-40 ? c to 85 ? c) at32uc3a3128s-ctur 144-ball tfbga reels industrial (-40 ? c to 85 ? c) at32uc3a3128 at32uc3a3128-alut 144-lead lqfp tray industrial (-40 ? c to 85 ? c) at32uc3a3128-alur 144-lead lqfp reels industrial (-40 ? c to 85 ? c) at32uc3a3128-ctut 144-ball tfbga tray industrial (-40 ? c to 85 ? c) at32uc3a3128-ctur 144-ball tfbga reels industrial (-40 ? c to 85 ? c) at32uc3a364s at32uc3a364s-alut 144-lead lqfp tray industrial (-40 ? c to 85 ? c) at32uc3a364s-alur 144-lead lqfp reels industrial (-40 ? c to 85 ? c) at32uc3a364s-ctut 144-ball tfbga tray industrial (-40 ? c to 85 ? c) at32uc3a364s-ctur 144-ball tfbga reels industrial (-40 ? c to 85 ? c) at32uc3a364 at32uc3a364-alut 144-lead lqfp tray industrial (-40 ? c to 85 ? c) at32uc3a364-alur 144-lead lqfp reels industrial (-40 ? c to 85 ? c) at32uc3a364-ctut 144-ball tfbga tray industrial (-40 ? c to 85 ? c) at32uc3a364-ctur 144-ball tfbga reels industrial (-40 ? c to 85 ? c) at32uc3a4256s at32uc3a4256s-c1ut 100-ball vfbga tray industrial (-40 ? c to 85 ? c) at32uc3a4256s-c1ur 100-ball vfbga reels industrial (-40 ? c to 85 ? c) at32uc3a4256 at32uc3a4256-c1ut 100-ball vfbga tray industrial (-40 ? c to 85 ? c) at32uc3a4256-c1ur 100-ball vfbga reels industrial (-40 ? c to 85 ? c) at32uc3a4128s AT32UC3A4128S-C1UT 100-ball vfbga tray industrial (-40 ? c to 85 ? c) at32uc3a4128s-c1ur 100-ball vfbga reels industrial (-40 ? c to 85 ? c) at32uc3a4128 at32uc3a4128-c1ut 100-ball vfbga tray industrial (-40 ? c to 85 ? c) at32uc3a4128-c1ur 100-ball vfbga reels industrial (-40 ? c to 85 ? c) at32uc3a464s at32uc3a464s-c1ut 100-ball vfbga tray industrial (-40 ? c to 85 ? c) at32uc3a464s-c1ur 100-ball vfbga reels industrial (-40 ? c to 85 ? c) at32uc3a464 at32uc3a464-c1ut 100-ball vfbga tray industrial (-40 ? c to 85 ? c) at32uc3a464-c1ur 100-ball vfbga reels industrial (-40 ? c to 85 ? c)
1011 32072d?04/2011 at32uc3a3/a4 38. errata 38.1 rev. h 38.1.1 general dmaca data transfer fa ils when ctlx.src_tr_width is not equal to ctlx.dst_tr_width fix/workaround for any dmaca transfer make sure ct lx.src_tr_width = ct lx.dst_tr_width. 38.1.2 processor and architecture ldm instruction with pc in the regist er list and without ++ increments rp for ldm with pc in the register list: the instruction behaves as if the ++ field is always set, ie the pointer is alwa ys updated. this happens even if the ++ field is cleared. specifically, the increment of the pointer is done in parallel with the testing of r12. fix/workaround none. instruction breakpoints affected on all mac instruction hardware breakpoints on mac instructions may corrupt the destination register of the mac instruction. fix/workaround place breakpoints on earlier or later instructions. when the main clock is rcsys, timer_clock5 is equal to pba clock when the main clock is gen erated from rcsys, timer_cl ock5 is equal to pba clock and not pba clock / 128. fix/workaround none. 38.1.3 mpu privilege violation when using interrupts in application mode with protected system stack if the system stack is protected by the mpu and an interrupt occurs in application mode, an mpu dtlb exception will occur. fix/workaround make a dtlb protection (write) exception handler which permits the interrupt request to be handled in privileged mode. 38.1.4 usb upcfgn.intfrq is irrelevant for isochronous pipe as a consequence, isochronous in and out tokens are sent every 1 ms (full speed), or every 125 us (high speed). fix/workaround forhigher polling time, the softwa re must freeze the pipe for the desired period in order to prevent any "extra" token.
1012 32072d?04/2011 at32uc3a3/a4 38.1.5 adc sleep mode activation needs addtionnal a to d conversion if the adc sleep mode is activated when the ad c is idle the adc w ill not enter sleep mode before after the next ad conversion. fix/workaround activate the sleep mode in the mode register and then perform an ad conversion. 38.1.6 usart iso7816 info register us_ner cannot be read the ner register always returns zero. fix/workaround none. the lin id is not transmitted in mode pdcm='0' fix/workaround using usart in mode lin master with the pdcm bit = '0', the linid written at the first address of the transmit buffer is not used. the linid must be written in the linir register, after the configuration and start of the pdca transfert. writing the linid in the linir regis- ter will start the transfert whenever the pdca transfer is ready. the linid interrupt is only available for the header reception and not available for the header transmission fix/workaround none. usart lin mode is not functional with the pdca if pdcm bit in linmr register is set to 1 if a pdca transfer is initiat ed in usart lin mode with pdcm bi t set to 1, the transfer never starts. fix/workaround only use pdcm=0 configuratio n with the pdca transfer. 38.1.7 spi spi disable does not work in slave mode spi disable does not work in slave mode. fix/workaround read the last received data, then perform a software reset. spi bad serial clock generation on 2nd chip_select when scbr = 1, cpol=1 and ncpha=0 when multiple cs are in use, if one of the baudrate equals to 1 and one of the others doesn't equal to 1, and cpol=1 and cpha=0, then an aditional pulse will be generated on sck. fix/workaround when multiple cs are in use, if one of the baudrate equals 1, the other must also equal 1 if cpol=1 and cpha=0. spi data transfer hangs with csr0.csaat==1 and mr.modfdis==0 when csr0.csaat==1 and mode fault detection is enabled (mr.modfdis==0), the spi module will not start a data transfer. fix/workaround disable mode fault detection by writing a one to mr.modfdis.
1013 32072d?04/2011 at32uc3a3/a4 disabling spi has no effect on flag tdre flag disabling spi has no effect on tdre whereas the write data command is filtered when spi is disabled. this means that as soon as the spi is disabled it becomes impossible to reset the tdre flag by writing in the tdr. so if the spi is disabled during a pdca transfer, the pdca will continue to write data in the tdr (as tdre stays hi gh) until its buffer is empty, and all data written after the disable command is lost. fix/workaround disable the pdca, insert 2 nops, disable spi. to continue the transfer: enable spi, enable pdca. 38.1.8 power manager clock sources will not be stopped in static sleep mode if the difference between cpu and pbx division factor is too high if the division factor between the cpu/hsb and pbx frequencies is more than 4 when going to a sleep mode where the system rc oscillator is turned off, then high speed clock sources will not be turned off. this will result in a significantly higher power consumption during the sleep mode. fix/workaround before going to sleep modes w here the system rc oscillator is stopped, make sure that the factor between the cpu/hsb and pbx frequencies is less than or equal to 4. 38.1.9 pdca pcontrol.chxres is non-functional pcontrol.chxres is non-func tional. counters are reset at power-on, and cannot be reset by software. fix/workaround software needs to keep history of performance counters. transfer error will stall a transm it peripheral handshake interface if a tranfer error is encountered on a channel transmitting to a peripheral, the peripheral handshake of the acti ve channel will stall and the pdca will not do any more transfers on the affected peripheral handshake interface. fix/workaround disable and then enable the peripheral after the transfer error. 38.1.10 aes urad (unspecified register access detection status) does not detect read accesses to the write-only keyw[5..8]r registers fix/workaround none. 38.1.11 hmatrix in the hmatrix pras and prbs regi sters mxpr fields are only two bits in the hmatrix pras and prbs registers mxpr fields are only two bits wide, instead of four bits. the unused bits are undefined when reading the registers. fix/workaround mask undefined bits when reading pras and prbs.
1014 32072d?04/2011 at32uc3a3/a4 38.1.12 twim twim sr.idle goes high immediately when nak is received when a nak is received and there is a non-zero number of bytes to be transmitted, sr.idle goes high immediately and does not wa it for the stop condition to be sent. this does not cause any problem just by itself, but can cause a problem if software waits for sr.idle to go high and then immediately disables the twim by writing a one to cr.mdis. disabling the twim causes the twck and twd pi ns to go high immediately, so the stop condition will not be tr ansmitted correctly. fix/workaround if possible, do not disable the twim. if it is absolutely necessary to disable the twim, there must be a software delay of at least two twck periods between the detection of sr.idle==1 and the disabling of the twim. twim twalm polarity is wrong the twalm signal in the twim is active high instead of active low. fix/workaround use an external inverter to invert the signal going into the twim. when using both twim and twis on the same pins, the twalm cannot be used. smbalert bit may be set after reset the smbus alert (smbalert) bit in the status register (sr) might be erroneously set after system reset. fix/workaround after system reset, clear the sr.smbalert bit before commencing any twi transfer. 38.1.13 twis clearing the nak bit before the btf bit is set locks up the twi bus when the twis is in transmit mode, clearing the nak received (nak) bit of the status reg- ister (sr) before the end of the acknowl edge/not acknowledge cycle will cause the twis to attempt to continue transmitting data, thus locking up the bus. fix/workaround clear sr.nak only after the byte transfer finished (btf) bit of the same register has been set. twis stretch on address match error when the twis stretches twck due to a slave address match, it also holds twd low for the same duration if it is to be receivi ng data. when twis releases twck, it releases twd at the same time. this can cause a twi timing violation. fix/workaround none. 38.1.14 ssc frame synchro and frame synchro data are delayed by one clock cycle the frame synchro and the frame synchro data are delayed from 1 ssc_clock when: - clock is ckdiv - the start is selected on either a frame synchro edge or a level - frame synchro data is enabled - transmit clock is gated on output (through cko field) fix/workaround transmit or receive clock must not be gated (by the mean of cko field) when start condition is performed on a generated frame synchro.
1015 32072d?04/2011 at32uc3a3/a4 38.1.15 flashc corrupted read in flash may happen after fuses write or erase operations (flashc lp, up, wgpb, egpb, ssb, pgpfb, eagpf commands) after a flash fuse write or erase operati on (flashc lp, up, wgpb, egpb, ssb, pgpfb, eagpf commands), reading (data read or code fetch) in flash may fail. this may lead to an exception or to other errors derived from this corrupted read access. fix/workaround before the flash fuse write or erase operat ion, enable the flash high speed mode (flashc hsen command). the flash fuse write or erase operations (flashc lp, up, wgpb, egpb, ssb, pgpfb, eagpf commands) must be issued from ram or through the ebi. after these commands, read 3 times one flash page initialized to 00h. disable the flash high speed mode (flashc hsdis command). it is then possible to safely read or code fetch the flash. 38.2 rev. e 38.2.1 general increased power consunption in vddio in sleep modes if the osc0 is enabled in crystal mode when entering a sleep mode where the osc0 is dis- abled, this will lead to an increased power consumption in vddio. fix/workaround disable the osc0 through the system control interface (scif) before going to any sleep mode where the osc0 is disabled, or pull down or up xin0 and xout0 with 1 mohm resistor. power consumption in static mode the power consumption in static mode can be up to 330a on some parts (typical at 25c) fix/workaround set to 1b bit corrs4 of the ecchrs mode register (md). in c-code: *((volatile int*) (0xfffe2404))= 0x400. dmaca data transfer fa ils when ctlx.src_tr_width is not equal to ctlx.dst_tr_width fix/workaround for any dmaca transfer make sure ct lx.src_tr_width = ct lx.dst_tr_width. 3.3v supply monitor is not available fgpfrlo[30:29] are reserved and should not be used by the application. fix/workaround none. service access bus (sab) can not access dmaca registers fix/workaround none. 38.2.2 processor and architecture ldm instruction with pc in the regist er list and without ++ increments rp for ldm with pc in the register list: the instruction behaves as if the ++ field is always set, ie the pointer is alwa ys updated. this happens even if the ++ field is cleared. specifically, the increment of the pointer is done in parallel with the testing of r12.
1016 32072d?04/2011 at32uc3a3/a4 fix/workaround none. instruction breakpoints affected on all mac instruction hardware breakpoints on mac instructions may corrupt the destination register of the mac instruction. fix/workaround place breakpoints on earlier or later instructions. when the main clock is rcsys, timer_clock5 is equal to pba clock when the main clock is gen erated from rcsys, timer_cl ock5 is equal to pba clock and not pba clock / 128. fix/workaround none. 38.2.3 mpu privilege violation when using interrupts in application mode with protected system stack if the system stack is protected by the mpu and an interrupt occurs in application mode, an mpu dtlb exception will occur. fix/workaround make a dtlb protection (write) exception handler which permits the interrupt request to be handled in privileged mode. 38.2.4 usb upcfgn.intfrq is irrelevant for isochronous pipe as a consequence, isochronous in and out tokens are sent every 1 ms (full speed), or every 125 us (high speed). fix/workaround forhigher polling time, the softwa re must freeze the pipe for the desired period in order to prevent any "extra" token. 38.2.5 adc sleep mode activation needs addtionnal a to d conversion if the adc sleep mode is activated when the ad c is idle the adc w ill not enter sleep mode before after the next ad conversion. fix/workaround activate the sleep mode in the mode register and then perform an ad conversion. 38.2.6 usart iso7816 info register us_ner cannot be read the ner register always returns zero. fix/workaround none. the lin id is not transmitted in mode pdcm='0' fix/workaround using usart in mode lin master with the pdcm bit = '0', the linid written at the first address of the transmit buffer is not used. the linid must be written in the linir register,
1017 32072d?04/2011 at32uc3a3/a4 after the configuration and start of the pdca transfert. writing the linid in the linir regis- ter will start the transfert whenever the pdca transfer is ready. the linid interrupt is only available for the header reception and not available for the header transmission fix/workaround none. usart lin mode is not functional with the pdca if pdcm bit in linmr register is set to 1 if a pdca transfer is initiat ed in usart lin mode with pdcm bi t set to 1, the transfer never starts. fix/workaround only use pdcm=0 configuratio n with the pdca transfer. the rts output does not f unction correctly in hardware handshaking mode the rts signal is not generated properly when the usart receives data in hardware hand- shaking mode. when the peripheral dma receive buffer becomes full, the rts output should go high, bu t it will stay low. fix/workaround do not use the hardware handshaking mode of the usart. if it is necessary to drive the rts output high when the peripheral dma receive buffer becomes full, use the normal mode of the usart. configure the peripheral dma controller to signal an interrupt when the receive buffer is full. in the interrupt handler code, write a one to the rtsdis bit in the usart control register (cr). this will drive th e rts output high. afte r the next dma trans- fer is started and a receive buffer is available, write a one to the rtsen bit in the usart cr so that rts will be driven low. iso7816 mode t1: rx impossible after any tx rx impossible after any tx. fix/workaround soft_reset on rx+ config us_mr + config_us_cr. 38.2.7 spi spi disable does not work in slave mode spi disable does not work in slave mode. fix/workaround read the last received data, then perform a software reset. spi bad serial clock generation on 2nd chip_select when scbr = 1, cpol=1 and ncpha=0 when multiple cs are in use, if one of the baudrate equals to 1 and one of the others doesn't equal to 1, and cpol=1 and cpha=0, then an aditional pulse will be generated on sck. fix/workaround when multiple cs are in use, if one of the baudrate equals 1, the other must also equal 1 if cpol=1 and cpha=0. spi data transfer hangs with csr0.csaat==1 and mr.modfdis==0 when csr0.csaat==1 and mode fault detection is enabled (mr.modfdis==0), the spi module will not start a data transfer. fix/workaround disable mode fault detection by writing a one to mr.modfdis.
1018 32072d?04/2011 at32uc3a3/a4 disabling spi has no effect on flag tdre flag disabling spi has no effect on tdre whereas the write data command is filtered when spi is disabled. this means that as soon as the spi is disabled it becomes impossible to reset the tdre flag by writing in the tdr. so if the spi is disabled during a pdca transfer, the pdca will continue to write data in the tdr (as tdre stays hi gh) until its buffer is empty, and all data written after the disable command is lost. fix/workaround disable the pdca, insert 2 nops, disable spi. to continue the transfer: enable spi, enable pdca. 38.2.8 power manager clock sources will not be stopped in static sleep mode if the difference between cpu and pbx division factor is too high if the division factor between the cpu/hsb and pbx frequencies is more than 4 when going to a sleep mode where the system rc oscillator is turned off, then high speed clock sources will not be turned off. this will result in a significantly higher power consumption during the sleep mode. fix/workaround before going to sleep modes w here the system rc oscillator is stopped, make sure that the factor between the cpu/hsb and pbx frequencies is less than or equal to 4. 38.2.9 pdca pcontrol.chxres is non-functional pcontrol.chxres is non-func tional. counters are reset at power-on, and cannot be reset by software. fix/workaround software needs to keep history of performance counters. transfer error will stall a transm it peripheral handshake interface if a tranfer error is encountered on a channel transmitting to a peripheral, the peripheral handshake of the acti ve channel will stall and the pdca will not do any more transfers on the affected peripheral handshake interface. fix/workaround disable and then enable the peripheral after the transfer error. 38.2.10 aes urad (unspecified register access detection status) does not detect read accesses to the write-only keyw[5..8]r registers fix/workaround none. 38.2.11 hmatrix in the hmatrix pras and prbs regi sters mxpr fields are only two bits in the hmatrix pras and prbs registers mxpr fields are only two bits wide, instead of four bits. the unused bits are undefined when reading the registers. fix/workaround mask undefined bits when reading pras and prbs.
1019 32072d?04/2011 at32uc3a3/a4 38.2.12 twim twim sr.idle goes high immediately when nak is received when a nak is received and there is a non-zero number of bytes to be transmitted, sr.idle goes high immediately and does not wa it for the stop condition to be sent. this does not cause any problem just by itself, but can cause a problem if software waits for sr.idle to go high and then immediately disables the twim by writing a one to cr.mdis. disabling the twim causes the twck and twd pi ns to go high immediately, so the stop condition will not be tr ansmitted correctly. fix/workaround if possible, do not disable the twim. if it is absolutely necessary to disable the twim, there must be a software delay of at least two twck periods between the detection of sr.idle==1 and the disabling of the twim. twim twalm polarity is wrong the twalm signal in the twim is active high instead of active low. fix/workaround use an external inverter to invert the signal going into the twim. when using both twim and twis on the same pins, the twalm cannot be used. smbalert bit may be set after reset the smbus alert (smbalert) bit in the status register (sr) might be erroneously set after system reset. fix/workaround after system reset, clear the sr.smbalert bit before commencing any twi transfer. 38.2.13 twis clearing the nak bit before the btf bit is set locks up the twi bus when the twis is in transmit mode, clearing the nak received (nak) bit of the status reg- ister (sr) before the end of the acknowl edge/not acknowledge cycle will cause the twis to attempt to continue transmitting data, thus locking up the bus. fix/workaround clear sr.nak only after the byte transfer finished (btf) bit of the same register has been set. twis stretch on address match error when the twis stretches twck due to a slave address match, it also holds twd low for the same duration if it is to be receivi ng data. when twis releases twck, it releases twd at the same time. this can cause a twi timing violation. fix/workaround none. 38.2.14 mci mci_clk features is not available on px12, px13 and px40 fix/workaround mci_clk feature is available on pa27 only. the busy signal of the responses r1b is not taken in account (excepting for cmd12 stop_transfer) it is not possible to know the busy status of the card during the response (r1b) for the com- mands cmd7, cmd28, cmd29, cmd38, cmd42, cmd56.
1020 32072d?04/2011 at32uc3a3/a4 fix/workaround the card busy line should be polled through the gpio pin for commands cmd7, cmd28, cmd29, cmd38, cmd42 and cmd56. the gpio alternate configuration should be restored after. 38.2.15 ssc frame synchro and frame synchro data are delayed by one clock cycle the frame synchro and the frame synchro data are delayed from 1 ssc_clock when: - clock is ckdiv - the start is selected on either a frame synchro edge or a level - frame synchro data is enabled - transmit clock is gated on output (through cko field) fix/workaround transmit or receive clock must not be gated (by the mean of cko field) when start condition is performed on a generated frame synchro. 38.3 rev. d 38.3.1 general dmaca data transfer fa ils when ctlx.src_tr_width is not equal to ctlx.dst_tr_width fix/workaround for any dmaca transfer make sure ct lx.src_tr_width = ct lx.dst_tr_width. 3.3v supply monitor is not available fgpfrlo[30:29] are reserved and should not be used by the application. fix/workaround none. service access bus (sab) can not access dmaca registers fix/workaround none. 38.3.2 processor and architecture ldm instruction with pc in the regist er list and without ++ increments rp for ldm with pc in the register list: the instruction behaves as if the ++ field is always set, ie the pointer is alwa ys updated. this happens even if the ++ field is cleared. specifically, the increment of the pointer is done in parallel with the testing of r12. fix/workaround none. instruction breakpoints affected on all mac instruction hardware breakpoints on mac instructions may corrupt the destination register of the mac instruction. fix/workaround place breakpoints on earlier or later instructions. when the main clock is rcsys, timer_clock5 is equal to pba clock when the main clock is gen erated from rcsys, timer_cl ock5 is equal to pba clock and not pba clock / 128.
1021 32072d?04/2011 at32uc3a3/a4 fix/workaround none. rete instruction does not clear sreg[l] from interrupts the rete instruction clears sreg[l] as expected from exceptions. fix/workaround when using the stcond instruct ion, clear sreg[l] in the stacked value of sr before returning from interrupts with rete. exceptions when system stack is protected by mpu rets behaves incorrectly when mpu is en abled and mpu is configured so thatsystem stack is not readable in unprivileged mode. fix/workaround workaround 1: make system stack readable in unprivileged mode, or workaround 2: return from supervisor mode using rete instead of rets. this requires: 1. changing the mode bits from 001b to 110b before issuing the instruction. updating the mode bits to the desired value must be done using a single mtsr instruction so it is done atomically. even if this step is described in general as not safe in the uc technical reference guide, it is safe in th is very specific case. 2. execute the rete instruction. in the hmatrix pras and prbs regi sters mxpr fields are only two bits in the hmatrix pras and prbs registers mxpr fields are only two bits wide, instead of four bits. the unused bits are undefined when reading the registers. fix/workaround mask undefined bits when reading pras and prbs. multiply instructions do not work on revd all the multiply instructions do not work. fix/workaround do not use the multiply instructions. 38.3.3 mpu privilege violation when using interrupts in application mode with protected system stack if the system stack is protected by the mpu and an interrupt occurs in application mode, an mpu dtlb exception will occur. fix/workaround make a dtlb protection (write) exception handler which permits the interrupt request to be handled in privileged mode. 38.3.4 usb upcfgn.intfrq is irrelevant for isochronous pipe as a consequence, isochronous in and out tokens are sent every 1 ms (full speed), or every 125 us (high speed). fix/workaround forhigher polling time, the softwa re must freeze the pipe for the desired period in order to prevent any "extra" token.
1022 32072d?04/2011 at32uc3a3/a4 38.3.5 adc sleep mode activation needs addtionnal a to d conversion if the adc sleep mode is activated when the ad c is idle the adc w ill not enter sleep mode before after the next ad conversion. fix/workaround activate the sleep mode in the mode register and then perform an ad conversion. 38.3.6 usart iso7816 info register us_ner cannot be read the ner register always returns zero. fix/workaround none. the lin id is not transmitted in mode pdcm='0' fix/workaround using usart in mode lin master with the pdcm bit = '0', the linid written at the first address of the transmit buffer is not used. the linid must be written in the linir register, after the configuration and start of the pdca transfert. writing the linid in the linir regis- ter will start the transfert whenever the pdca transfer is ready. the linid interrupt is only available for the header reception and not available for the header transmission fix/workaround none. usart lin mode is not functional with the pdca if pdcm bit in linmr register is set to 1 if a pdca transfer is initiat ed in usart lin mode with pdcm bi t set to 1, the transfer never starts. fix/workaround only use pdcm=0 configuratio n with the pdca transfer. the rts output does not f unction correctly in hardware handshaking mode the rts signal is not generated properly when the usart receives data in hardware hand- shaking mode. when the peripheral dma receive buffer becomes full, the rts output should go high, bu t it will stay low. fix/workaround do not use the hardware handshaking mode of the usart. if it is necessary to drive the rts output high when the peripheral dma receive buffer becomes full, use the normal mode of the usart. configure the peripheral dma controller to signal an interrupt when the receive buffer is full. in the interrupt handler code, write a one to the rtsdis bit in the usart control register (cr). this will drive th e rts output high. afte r the next dma trans- fer is started and a receive buffer is available, write a one to the rtsen bit in the usart cr so that rts will be driven low. iso7816 mode t1: rx impossible after any tx rx impossible after any tx. fix/workaround soft_reset on rx+ config us_mr + config_us_cr.
1023 32072d?04/2011 at32uc3a3/a4 38.3.7 spi spi disable does not work in slave mode spi disable does not work in slave mode. fix/workaround read the last received data, then perform a software reset. spi bad serial clock generation on 2nd chip_select when scbr = 1, cpol=1 and ncpha=0 when multiple cs are in use, if one of the baudrate equals to 1 and one of the others doesn't equal to 1, and cpol=1 and cpha=0, then an aditional pulse will be generated on sck. fix/workaround when multiple cs are in use, if one of the baudrate equals 1, the other must also equal 1 if cpol=1 and cpha=0. spi data transfer hangs with csr0.csaat==1 and mr.modfdis==0 when csr0.csaat==1 and mode fault detection is enabled (mr.modfdis==0), the spi module will not start a data transfer. fix/workaround disable mode fault detection by writing a one to mr.modfdis. disabling spi has no effect on flag tdre flag disabling spi has no effect on tdre whereas the write data command is filtered when spi is disabled. this means that as soon as the spi is disabled it becomes impossible to reset the tdre flag by writing in the tdr. so if the spi is disabled during a pdca transfer, the pdca will continue to write data in the tdr (as tdre stays hi gh) until its buffer is empty, and all data written after the disable command is lost. fix/workaround disable the pdca, insert 2 nops, disable spi. to continue the transfer: enable spi, enable pdca. 38.3.8 power manager clock sources will not be stopped in static sleep mode if the difference between cpu and pbx division factor is too high if the division factor between the cpu/hsb and pbx frequencies is more than 4 when going to a sleep mode where the system rc oscillator is turned off, then high speed clock sources will not be turned off. this will result in a significantly higher power consumption during the sleep mode. fix/workaround before going to sleep modes w here the system rc oscillator is stopped, make sure that the factor between the cpu/hsb and pbx frequencies is less than or equal to 4. 38.3.9 pdca pcontrol.chxres is non-functional pcontrol.chxres is non-func tional. counters are reset at power-on, and cannot be reset by software. fix/workaround software needs to keep history of performance counters.
1024 32072d?04/2011 at32uc3a3/a4 transfer error will stall a transm it peripheral handshake interface if a tranfer error is encountered on a channel transmitting to a peripheral, the peripheral handshake of the acti ve channel will stall and the pdca will not do any more transfers on the affected peripheral handshake interface. fix/workaround disable and then enable the peripheral after the transfer error. 38.3.10 aes urad (unspecified register access detection status) does not detect read accesses to the write-only keyw[5..8]r registers fix/workaround none. 38.3.11 hmatrix in the hmatrix pras and prbs regi sters mxpr fields are only two bits in the hmatrix pras and prbs registers mxpr fields are only two bits wide, instead of four bits. the unused bits are undefined when reading the registers. fix/workaround mask undefined bits when reading pras and prbs. 38.3.12 twim twim sr.idle goes high immediately when nak is received when a nak is received and there is a non-zero number of bytes to be transmitted, sr.idle goes high immediately and does not wa it for the stop condition to be sent. this does not cause any problem just by itself, but can cause a problem if software waits for sr.idle to go high and then immediately disables the twim by writing a one to cr.mdis. disabling the twim causes the twck and twd pi ns to go high immediately, so the stop condition will not be tr ansmitted correctly. fix/workaround if possible, do not disable the twim. if it is absolutely necessary to disable the twim, there must be a software delay of at least two twck periods between the detection of sr.idle==1 and the disabling of the twim. twim twalm polarity is wrong the twalm signal in the twim is active high instead of active low. fix/workaround use an external inverter to invert the signal going into the twim. when using both twim and twis on the same pins, the twalm cannot be used. 38.3.13 twis twis version register is zero twis version register (vr) is zero instead of 0x110. fix/workaround none.
1025 32072d?04/2011 at32uc3a3/a4 38.3.14 mci the busy signal of the responses r1b is not taken in account (excepting for cmd12 stop_transfer) it is not possible to know the busy status of the card during the response (r1b) for the com- mands cmd7, cmd28, cmd29, cmd38, cmd42, cmd56. fix/workaround the card busy line should be polled through the gpio pin for commands cmd7, cmd28, cmd29, cmd38, cmd42 and cmd56. the gpio alternate configuration should be restored after. 38.3.15 ssc frame synchro and frame synchro data are delayed by one clock cycle the frame synchro and the frame synchro data are delayed from 1 ssc_clock when: - clock is ckdiv - the start is selected on either a frame synchro edge or a level - frame synchro data is enabled - transmit clock is gated on output (through cko field) fix/workaround transmit or receive clock must not be gated (by the mean of cko field) when start condition is performed on a generated frame synchro.
1026 32072d?04/2011 at32uc3a3/a4 39. datasheet revision history please note that the referring page numbers in th is section are referred to this document. the referring revision in this section are referring to the document revision. 39.1 rev. d ? 04/11 39.2 rev. c ? 03/10 39.3 rev. b ? 08/09 39.4 rev. a ? 03/09 1. updated errata for revision h and e 2. updated reset sequence 3. updated peripherals? current consumption and others minor electrical charateristics 4. updated peripherals chapters 1. updated the datasheet with new revision h features. 1. updated the datasheet with new device at32uc3a4. 1. initial revision.
1027 32072d04/2011 at32uc3a3/a4 table of contents 1 description ............ .............. .............. ............... .............. .............. ............ 3 2 overview ............ ................ ................ ............... .............. .............. ............ 4 2.1 block diagram ...................................................................................................4 2.2 configuration summary .....................................................................................5 3 package and pinout ................. ................ ................. ................ ............... 6 3.1 package .............................................................................................................6 3.2 peripheral multiplexing on i/o lines ...................................................................9 3.3 signal descriptions ..........................................................................................14 3.4 i/o line considerations ...................................................................................19 3.5 power considerations .....................................................................................20 4 processor and architecture .... ................ ................. ................ ............. 21 4.1 features ..........................................................................................................21 4.2 avr32 architecture .........................................................................................21 4.3 the avr32uc cpu ........................................................................................22 4.4 programming model ........................................................................................26 4.5 exceptions and interrupts ................................................................................30 4.6 module configuration ......................................................................................34 5 memories ............... .............. .............. ............... .............. .............. .......... 35 5.1 embedded memories ......................................................................................35 5.2 physical memory map .....................................................................................35 5.3 peripheral address map ..................................................................................36 5.4 cpu local bus mapping .................................................................................38 6 boot sequence ............. ................. ................ ................. .............. .......... 40 6.1 starting of clocks ............................................................................................40 6.2 fetching of initial instructions ..........................................................................40 7 power manager (pm) .. ................ ................. ................ ................. .......... 41 7.1 features ..........................................................................................................41 7.2 overview ..........................................................................................................41 7.3 block diagram .................................................................................................42 7.4 product dependencies ....................................................................................43 7.5 functional description .....................................................................................43 7.6 user interface ..................................................................................................55
1028 32072d04/2011 at32uc3a3/a4 8 real time counter (rtc) ... .............. ............... .............. .............. .......... 80 8.1 features ..........................................................................................................80 8.2 overview ..........................................................................................................80 8.3 block diagram .................................................................................................80 8.4 product dependencies ....................................................................................80 8.5 functional description .....................................................................................81 8.6 user interface ..................................................................................................83 9 watchdog timer (wdt) ........... ................ ................. ................ ............. 92 9.1 features ..........................................................................................................92 9.2 overview ..........................................................................................................92 9.3 block diagram .................................................................................................92 9.4 product dependencies ....................................................................................92 9.5 functional description .....................................................................................93 9.6 user interface ..................................................................................................93 10 interrupt controller (intc) . .............. ............... .............. .............. .......... 96 10.1 features ..........................................................................................................96 10.2 overview ..........................................................................................................96 10.3 block diagram .................................................................................................96 10.4 product dependencies ....................................................................................97 10.5 functional description .....................................................................................97 10.6 user interface ................................................................................................100 10.7 interrupt request signal map ........................................................................104 11 external interrupt controller (eic) ..... .............. .............. ............ ........ 107 11.1 features ........................................................................................................107 11.2 overview ........................................................................................................107 11.3 block diagram ...............................................................................................108 11.4 i/o lines description .....................................................................................108 11.5 product dependencies ..................................................................................108 11.6 functional description ...................................................................................109 11.7 user interface ................................................................................................113 11.8 module configuration ....................................................................................129 12 flash controller (flashc) ... ................ ................. ................ ............. 130 12.1 features ........................................................................................................130 12.2 overview ........................................................................................................130 12.3 product dependencies ...................................................................................130
1029 32072d04/2011 at32uc3a3/a4 12.4 functional description ....................................................................................131 12.5 flash commands ...........................................................................................133 12.6 general-purpose fuse bits .............................................................................135 12.7 security bit .....................................................................................................137 12.8 user interface ................................................................................................138 12.9 fuses settings ...............................................................................................146 12.10 serial number in the factory page ..................................................................147 12.11 module configuration .....................................................................................147 13 hsb bus matrix (hmatrix) .. ................ ................. ................ ............. 148 13.1 features ........................................................................................................148 13.2 overview ........................................................................................................148 13.3 product dependencies ..................................................................................148 13.4 functional description ...................................................................................148 13.5 user interface ................................................................................................152 13.6 bus matrix connections .................................................................................160 14 external bus interface (ebi ) ................ .............. .............. ............ ........ 162 14.1 features ........................................................................................................162 14.2 overview ........................................................................................................162 14.3 block diagram ...............................................................................................163 14.4 i/o lines description .....................................................................................164 14.5 product dependencies ..................................................................................165 14.6 functional description ...................................................................................167 14.7 application example ......................................................................................174 15 static memory controller (smc) ......... .............. .............. ............ ........ 177 15.1 features ........................................................................................................177 15.2 overview ........................................................................................................177 15.3 block diagram ...............................................................................................178 15.4 i/o lines description .....................................................................................178 15.5 product dependencies ..................................................................................178 15.6 functional description ...................................................................................179 15.7 user interface ................................................................................................211 16 sdram controller (sdramc) ................ ................. ................ ........... 218 16.1 features ........................................................................................................218 16.2 overview ........................................................................................................218 16.3 block diagram ...............................................................................................219
1030 32072d04/2011 at32uc3a3/a4 16.4 i/o lines description .....................................................................................219 16.5 application example ......................................................................................220 16.6 product dependencies ..................................................................................221 16.7 functional description ...................................................................................222 16.8 user interface ................................................................................................231 17 error corrected code c ontroller (ecchrs) ........... ................ ........... 245 17.1 features ........................................................................................................245 17.2 overview ........................................................................................................245 17.3 block diagram ...............................................................................................246 17.4 product dependencies ..................................................................................246 17.5 functional description ...................................................................................247 17.6 user interface ...............................................................................................253 17.7 module configuration ....................................................................................279 18 peripheral dma controller (pdca) ............. .............. .............. ........... 280 18.1 features ........................................................................................................280 18.2 overview ........................................................................................................280 18.3 block diagram ...............................................................................................281 18.4 product dependencies ..................................................................................281 18.5 functional description ...................................................................................282 18.6 performance monitors ...................................................................................284 18.7 user interface ................................................................................................285 18.8 module configuration ....................................................................................313 19 dma controller (dm aca) .................... .............. .............. ............ ........ 315 19.1 features ........................................................................................................315 19.2 overview ........................................................................................................315 19.3 block diagram ...............................................................................................316 19.4 product dependencies ..................................................................................316 19.5 functional description ...................................................................................317 19.6 arbitration for hsb master interface ..............................................................322 19.7 memory peripherals ......................................................................................322 19.8 handshaking interface ...................................................................................322 19.9 dmaca transfer types ................................................................................324 19.10 programming a channel ................................................................................328 19.11 disabling a channel prior to transfer completion ........................................345 19.12 user interface ................................................................................................347
1031 32072d04/2011 at32uc3a3/a4 19.13 module configuration ....................................................................................379 20 general-purpose input/output controller (gpio) .... .............. ........... 380 20.1 features ........................................................................................................380 20.2 overview ........................................................................................................380 20.3 block diagram ...............................................................................................380 20.4 product dependencies ..................................................................................380 20.5 functional description ...................................................................................381 20.6 user interface ................................................................................................385 20.7 programming examples ................................................................................400 20.8 module configuration .....................................................................................402 21 serial peripheral interface (spi) ................ ................ .............. ........... 403 21.1 features ........................................................................................................403 21.2 overview ........................................................................................................403 21.3 block diagram ...............................................................................................404 21.4 application block diagram .............................................................................404 21.5 i/o lines description .....................................................................................405 21.6 product dependencies ..................................................................................405 21.7 functional description ...................................................................................405 21.8 user interface ................................................................................................416 21.9 module configuration ....................................................................................442 22 two-wire slave interface (twi s) ................. .............. .............. ........... 443 22.1 features ........................................................................................................443 22.2 overview ........................................................................................................443 22.3 list of abbreviations ......................................................................................444 22.4 block diagram ...............................................................................................444 22.5 application block diagram .............................................................................445 22.6 i/o lines description .....................................................................................445 22.7 product dependencies ..................................................................................445 22.8 functional description ...................................................................................446 22.9 user interface ................................................................................................456 22.10 module configuration ....................................................................................472 23 two-wire master interface (twim) .............. .............. .............. ........... 473 23.1 features ........................................................................................................473 23.2 overview ........................................................................................................473 23.3 list of abbreviations ......................................................................................474
1032 32072d04/2011 at32uc3a3/a4 23.4 block diagram ...............................................................................................475 23.5 application block diagram2 ...........................................................................475 23.6 i/o lines description .....................................................................................475 23.7 product dependencies ..................................................................................476 23.8 functional description ...................................................................................477 23.9 user interface ................................................................................................489 23.10 module configuration ....................................................................................506 24 synchronous serial controller (ssc) .... ................. ................ ........... 507 24.1 features ........................................................................................................507 24.2 overview ........................................................................................................507 24.3 block diagram ...............................................................................................508 24.4 application block diagram .............................................................................508 24.5 i/o lines description .....................................................................................509 24.6 product dependencies ..................................................................................509 24.7 functional description ...................................................................................509 24.8 ssc application examples ............................................................................521 24.9 user interface ................................................................................................523 25 universal synchro nous asynchronous receiver tr ansmitter (usart) 545 25.1 features ........................................................................................................545 25.2 overview ........................................................................................................545 25.3 block diagram ...............................................................................................546 25.4 i/o lines description ....................................................................................547 25.5 product dependencies ..................................................................................548 25.6 functional description ...................................................................................549 25.7 user interface ................................................................................................605 25.8 module configuration ....................................................................................634 26 hi-speed usb on-the-go in terface (usbb) ............. .............. ........... 636 26.1 features ........................................................................................................636 26.2 overview ........................................................................................................636 26.3 block diagram ...............................................................................................637 26.4 application block diagram .............................................................................638 26.5 i/o lines description .....................................................................................640 26.6 product dependencies ..................................................................................641 26.7 functional description ...................................................................................642
1033 32072d04/2011 at32uc3a3/a4 26.8 user interface ................................................................................................677 26.9 module configuration ....................................................................................760 27 timer/counter (tc) ........... .............. .............. .............. .............. ........... 761 27.1 features ........................................................................................................761 27.2 overview ........................................................................................................761 27.3 block diagram ...............................................................................................762 27.4 i/o lines description .....................................................................................762 27.5 product dependencies ..................................................................................762 27.6 functional description ...................................................................................763 27.7 user interface ................................................................................................778 27.8 module configuration ....................................................................................801 28 analog-to-digital converte r (adc) ....... ................. ................ ............. 802 28.1 features ........................................................................................................802 28.2 overview ........................................................................................................802 28.3 block diagram ...............................................................................................803 28.4 i/o lines description .....................................................................................803 28.5 product dependencies ..................................................................................803 28.6 functional description ...................................................................................804 28.7 user interface ................................................................................................809 28.8 module configuration ....................................................................................822 29 hsb bus performance moni tor (busmon) .............. .............. ........... 823 29.1 features ........................................................................................................823 29.2 overview ........................................................................................................823 29.3 block diagram ...............................................................................................823 29.4 product dependencies ..................................................................................824 29.5 functional description ...................................................................................824 29.6 user interface ................................................................................................825 29.7 module configuration ....................................................................................832 30 multimedia card interface (m ci) ........... ................. ................ ............. 833 30.1 features ........................................................................................................833 30.2 overview ........................................................................................................833 30.3 block diagram ...............................................................................................834 30.4 i/o lines description .....................................................................................835 30.5 product dependencies ..................................................................................835 30.6 functional description ...................................................................................835
1034 32072d04/2011 at32uc3a3/a4 30.7 user interface ................................................................................................853 30.8 module configuration ....................................................................................881 31 memory stick interface (msi) ................ ................. ................ ............. 882 31.1 features ........................................................................................................882 31.2 overview ........................................................................................................882 31.3 block diagram ...............................................................................................883 31.4 product dependencies ..................................................................................883 31.5 connection to a memory stick .......................................................................884 31.6 functional description ...................................................................................885 31.7 user interface ................................................................................................888 32 advanced encryption standard (aes) ............. .............. ............ ........ 907 32.1 features ........................................................................................................907 32.2 overview ........................................................................................................907 32.3 product dependencies ..................................................................................907 32.4 functional description ...................................................................................908 32.5 user interface ................................................................................................914 32.6 module configuration ....................................................................................929 33 audio bitstream dac (abdac) .............. ................. ................ ........... 930 33.1 features ........................................................................................................930 33.2 overview ........................................................................................................930 33.3 block diagram ...............................................................................................931 33.4 i/o lines description .....................................................................................931 33.5 product dependencies ..................................................................................931 33.6 functional description ...................................................................................932 33.7 user interface ................................................................................................935 34 programming and debugging .. ................. ................ .............. ........... 943 34.1 overview ........................................................................................................943 34.2 service access bus .......................................................................................943 34.3 on-chip debug (ocd) ..................................................................................945 34.4 jtag and boundary-scan (jtag) .................................................................952 34.5 jtag instruction summary ...........................................................................960 35 electrical characteristics ... .............. ............... .............. .............. ........ 977 35.1 absolute maximum ratings* .........................................................................977 35.2 dc characteristics .........................................................................................978
1035 32072d04/2011 at32uc3a3/a4 35.3 i/o pin characteristics ...................................................................................979 35.4 regulator characteristics ...............................................................................980 35.5 analog characteristics ...................................................................................981 35.6 power consumption ......................................................................................985 35.7 system clock characteristics ........................................................................988 35.8 oscillator characteristics ...............................................................................989 35.9 adc characteristics ......................................................................................991 35.10 usb transceiver characteristics ...................................................................992 35.11 ebi timings ...................................................................................................994 35.12 jtag characteristics ...................................................................................1000 35.13 spi characteristics ......................................................................................1001 35.14 mci ..............................................................................................................1003 35.15 flash memory characteristics .....................................................................1004 36 mechanical characteristics ..... ................ ................. .............. ........... 1005 36.1 thermal considerations ..............................................................................1005 36.2 package drawings .......................................................................................1006 36.3 soldering profile ..........................................................................................1009 37 ordering information .......... ................. ................ ................. ............. 1010 38 errata ........... ................ ................ ................. .............. .............. ........... 1011 38.1 rev. h ..........................................................................................................1011 38.2 rev. e ..........................................................................................................1015 38.3 rev. d ..........................................................................................................1020 39 datasheet revision history ................ ................ ................. ............. 1026 39.1 rev. d ? 04/11 .............................................................................................1026 39.2 rev. c ? 03/10 .............................................................................................1026 39.3 rev. b ? 08/09 .............................................................................................1026 39.4 rev. a ? 03/09 .............................................................................................1026
32072d04/2011 headquarters international atmel corporation 2325 orchard parkway san jose, ca 95131 usa tel : (+1)(408) 441-0311 fax : (+1)(408) 487-2600 www.atmel.com atmel asia limited unit 1-5 & 16, 19/f bea tower, millennium city 5 418 kwun tong road kwun tong, kowloon hong kong tel : (+852) 2245-6100 fax : (+852) 2722-1369 atmel munich gmbh business campus parkring 4 d-85748 garching b. munich germany tel : (+49) 89-31970-0 fax : (+49) 89-3194621 atmel japan 9f, tonetsu shinkawa bldg. 1-24-8 shinkawa chuo-ku, tokyo 104-0033 japan tel : (+81)(3) 3523-3551 fax : (+81)(3) 3523-7581 product contact web site www.atmel.com technical support avr32@atmel.com sales contact www.atmel.com/contacts literature requests www.atmel.com/literature ? 2011 atmel corporation. all rights reserved. / rev. corp072610 atmel, logo and combinations thereof, and others are registered tr ademarks or trademarks of atmel corporation or its subsidiari es. other terms and product names may be trademarks of others. disclaimer: the information in this document is provided in connection with atmel products. no license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of atmel products. except as set forth in the atmel terms and condi- tions of sales located on the atmel website, atmel assumes no liability whatsoever and disclaims any express, implied or statut ory warranty relating to its products including, but not limited to , the implied warranty of merchantability, fitness for a particu lar purpose, or non-infringement. in no event shall atmel be liable for any direct, indirect, conseque ntial, punitive, special or i nciden- tal damages (including, without limitation, da mages for loss and profits, business interr uption, or loss of information) arisin g out of the use or inability to use this document, even if atmel has been advised of the possibility of such damages. atmel makes no representations or warranties with respect to the accuracy or comp leteness of the contents of this document and reserves the rig ht to make changes to specifications and product descriptions at any time without notice. atmel does not make any commitment to update the information contained her ein. unless specifically provided otherwise, atmel products are not suitable for, and shall not be used in, automotive applications. atmel products are not inten ded, authorized, or warranted for use as components in applications intended to support or sustain life.


▲Up To Search▲   

 
Price & Availability of AT32UC3A4128S-C1UT

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X